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.

Arrange Filters into stacks

A strategy for composing your applications

http4k Core
Authentication for HTTP services

Recipes for how to secure and authenticate HTTP services

http4k Core
Client as a function

Recipes for using http4k to consume HTTP services

http4k Core
Configure an OAuth_Server

Recipe for using http4k to create an authorization server that provides an authorization code access flow

http4k Core
Create a custom JSON marshaller

Recipes for using JSON in http4k applications with a variety of popular JSON APIS

http4k Core
Customise a Server backend

How to use write custom servers backends

http4k Core
Deploy WebJars

Recipe for using WebJars with http4k

http4k Core
Implement your own clients

How to implement your own clients for the Connect pattern

http4k Connect
Integrate with OpenAPI

Recipes for using the http4k-contract module to provide typesafe endpoints with automatically generated OpenAPI documentation

http4k Core
Leverage GraphQL

Recipe for using GraphQL plugins

http4k Core
Lookup a user principal

Recipes for looking up and populating a user principal from a request

http4k Core
Make HTTP calls in parallel

Recipe to make HTTP calls in parallel using a ThreadPoolExecutor

http4k Core
Make JSON Faster

Recipes to make JSON faster through the use of lighter reflection or code generation

http4k Core
Monitor http4k

How to monitor http4k endpoints and applications

http4k Core
Pimp your Connect API Clients with KSP!

How to use KSP to generate extension functions for your Connect clients

http4k Connect
Record and replay HTTP traffic

Recipes for using http4k to record and replay HTTP traffic

http4k Core
Redoc and Swagger UI

Create a Redoc or Swagger UI for your REST API

http4k Core
Request Contexts

Recipes for using http4k with per-request context objects

http4k Core
Routing API (Advanced)

Recipes for using the http4k composable routing API, including serving static content

http4k Core
Routing API (Simple)

Recipes for using the http4k composable routing API

http4k Core
Self Document Systems with Tests

Recipe for creating a Distributed Tracing Tree

http4k Core
Serve SSE

Recipes for using http4k with Server-Sent Events

http4k Core
Serve Websocket

Recipes for using http4k with websockets

http4k Core
Server-as-a-Function

The simplest example of an http4k application

http4k Core
Structure your logs with Events

Recipe for using http4k Events to send structured logs to external log sinks

http4k Core
Test using Service Virtualisation

Implementing Service Virtualisation using Servirtium contracts

http4k Core
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

http4k Core
Use a custom OAuth provider

Recipe for using http4k with custom OAuth provider

http4k Core
Use a Server backend

Recipes for using http4k with the various Server backends

http4k Core
Use a templating engine

Recipes for using server-side templating engines with http4k applications, including hot-reload functionality

http4k Core
Use Auto Content Negotiation

Recipes for using the Auto Content Negotiation Lens to marshall and unmarshall HTTP messages of various formats

http4k Core
Use HTML Forms

Recipes for using http4k with HTML forms

http4k Core
Use Multipart Forms

Recipes for using http4k with Multipart forms

http4k Core
Write different test types

Recipes for testing http4k applications

http4k Core
pumb