This helper creates a simple JSON API that accepts JSON request data and returns a JSON response. It can be used two different ways, depending on the callback's signature. The incoming data is an object with three properties:
- "method": the request method used
- "body": the data sent in the body of the request
- "query": any query parameters sent in the request
If the "arity" (the number of arguments) of the provided callback function is 1, then you can return a response directly, or a promise that eventually resolves to the data. Here's an example use: https://tonicdev.com/tonic/json-endpoint-example-1
If the "arity" is 2, then the second parameter is a "done" callback that you should call yourself whenever you want to return a response. You can pass the response as the only argument to the callback. Here's an example use: https://tonicdev.com/tonic/json-endpoint-example-2