To invoke an endpoint, you need to set input object with required apiName
option and optional headers
, queryParams
, and body
options. API status code response > 299 are thrown as an ApiError
instance. The error instance provides name
and message
properties parsed from the response.
To learn more about Lambda Proxy Integration, please visit Amazon API Gateway Developer Guide.
If you are using a REST API which is generated with Amplify CLI, your backend is created with Lambda Proxy Integration, and you can access your query parameters & body within your Lambda function via the event object:
Alternatively, you can update your backend file which is located at amplify/backend/function/[your-lambda-function]/app.js
with the middleware:
Accessing Query Parameters with Serverless Express
In your request handler use req.apiGateway.event
or req.query
:
Then you can use query parameters in your path as follows:
Accessing response payloadYou can consume the response payload by accessing the body
property of the response object. Depending on the use case and the content type of the body, you can consume they payload in string, blob or JSON.
You can not consume the response payload more than once.
Access HTTP response from errorsThe REST API handler may throw an ApiError
error instance. If the error is caused by an HTTP response with a non-2xx status code, the error instance will provide a response
property. The response
property contains following properties:
statusCode
: HTTP status codeheaders
: HTTP response headersbody
: HTTP response body as a stringThe following example shows how to access the HTTP response from an ApiError
instance, so that you can handle the error response from your REST API endpoint:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4