How-To Guides
The meat of the http4k documentation is in this section, in which you’ll find ready made solutions to many common use-cases. Because if you’ve got something to achieve - it’s pretty likely that we’ve probably come across it already 😉. Check out the nav on the left for the list of recipes.
The format for the recipes contains:
- Required Gradle dependencies
- A brief description of the problem
- Fully runnable code example displaying the solution.
Think of it like a mini StackOverflow - but better because you’ve got the entire solution available to adapt to your particular use-case - 😃.
As a community-driven project, we would welcome new or updated recipes to make http4k easier to use. The format of the new and updated recipes should follow this Markdown template.
Read more about the theory behind How-to guides here.
Authentication for HTTP services
Recipes for how to secure and authenticate HTTP services
Configure an OAuth_Server
Recipe for using http4k to create an authorization server that provides an authorization code access flow
Create a custom JSON marshaller
Recipes for using JSON in http4k applications with a variety of popular JSON APIS
Implement your own clients
How to implement your own clients for the Connect pattern
Integrate with OpenAPI
Recipes for using the http4k-contract module to provide typesafe endpoints with automatically generated OpenAPI documentation
Lookup a user principal
Recipes for looking up and populating a user principal from a request
Make HTTP calls in parallel
Recipe to make HTTP calls in parallel using a ThreadPoolExecutor
Make JSON Faster
Recipes to make JSON faster through the use of lighter reflection or code generation
Pimp your Connect API Clients with KSP!
How to use KSP to generate extension functions for your Connect clients
Record and replay HTTP traffic
Recipes for using http4k to record and replay HTTP traffic
Routing API (Advanced)
Recipes for using the http4k composable routing API, including serving static content
Structure your logs with Events
Recipe for using http4k Events to send structured logs to external log sinks
Test using Service Virtualisation
Implementing Service Virtualisation using Servirtium contracts
Typesafe your API with lenses
Recipes for using the inbuilt http4k Lens API to marshall HTTP messages on and off the wire in a typesafe fashion
Use a templating engine
Recipes for using server-side templating engines with http4k applications, including hot-reload functionality
Use Auto Content Negotiation
Recipes for using the Auto Content Negotiation Lens to marshall and unmarshall HTTP messages of various formats