dev.mccue/microhttp-json
dev.mccue.microhttp.json
bowbahdoe/microhttp-json
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
.
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
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(
.objectBuilder()
Json.put("name", "bob")
.build()
);
}
}