Middleware and Helpers
Gatsby Functions provides an Express-like architecture that simplifies building Node.js APIs. We include a number of middlewares to parse common request data as well as response helpers.
We parse commonly used data types. You can parse more by adding custom middleware. Data available by default on the
- Cookies at
- URL Queries (e.g.
- Form parameters and data at
- JSON POST bodies at
- Files uploaded from forms at
res.send(body)— returns the response. The
bodycan be a
res.json(body)— returns a JSON response. The
bodycan be any value that can be seralized with
res.status(statusCode)— set the HTTP status for the response. Defaults to
res.redirect([statusCode], url)— Returns a redirect to a URL. Optionally set the statusCode which defaults to
Custom Connect/Express middleware are supported.
An example of how to add CORS support to a Function:
Generally useful for file upload support.
This is not yet supported. Add a comment in the discussion if this is an important use case for you.