dev.mccue.microhttp.json

What is it

dev.mccue.microhttp.json provides JsonResponse, a class which implements IntoResponse and thus can be used alongside microhttp and microhttp-handler to produce responses which contain html.

It automatically adds the appropriate Content-Type header, determines the HTTP reason phrase with reasonphrase, and accepts the Json type provided by dev.mccue.json.

Why use it

If you are using microhttp with microhttp-handler, it boxes up the logic needed in order to return json responses. This would otherwise be cumbersome to write at every needed location

Getting Started

import dev.mccue.microhttp.handler.RouteHandler;
import dev.mccue.microhttp.json.JsonResponse;

import java.util.regex.Pattern;
import java.util.regex.Matcher;


class BasicHandler extends RouteHandler {
    IndexHandler() {
        super("GET", Pattern.compile("/"));
    }

    @Override
    public JsonResponse handleRoute(
            Matcher matcher,
            Request request
    ) {
        return new JsonResponse(
                Json.objectBuilder()
                    .put("name", "bob")
                    .build()
        );
    }
}

<- Index