description |
---|
Overview of the `api` module. |
Overview of the api
module in the sst/node
package.
import { ... } from "sst/node/api"
The api
module has the following exports.
The properties let you access the resources that are bound to the function.
This module helps with accessing Api
constructs.
import { Api } from "sst/node/api";
Type : string
The URL of the API. If custom domain is enabled, this is the custom domain URL of the API.
console.log(Api.myApi.url);
This module helps with accessing AppSyncApis.
import { AppSyncApi } from "sst/node/api";
console.log(AppSyncApi.myApi.url);
Type : string
The URL of the API. If custom domain is enabled, this is the custom domain URL of the API.
This module helps with accessing WebSocketApis.
import { WebSocketApi } from "sst/node/api";
console.log(WebSocketApi.myApi.url);
Type : string
The URL of the API. If custom domain is enabled, this is the custom domain URL of the API.
This module helps with accessing ApiGatewayV1Apis.
import { ApiGatewayV1Api } from "sst/node/api";
console.log(ApiGatewayV1Api.myApi.url);
Type : string
The URL of the API. If custom domain is enabled, this is the custom domain URL of the API.
The handlers can wrap around your Lambda function handler.
The ApiHandler
provides a function that can be used to implement the API handler function.
import { useBody, ApiHandler } from "sst/node/api";
export const handler = ApiHandler((event) => {
const body = useBody();
// ...
});
The hooks are functions that have access to the current invocation.
This hook returns the request body.
import { useBody } from "sst/node/api";
const body = useBody();
This hook returns the request body in JSON decoded format.
import { useJsonBody } from "sst/node/api";
const json = useJsonBody();
This hook returns a request cookie.
import { useCookie } from "sst/node/api";
const cookie = useCookie("token");
This hook returns all request cookies.
import { useCookies } from "sst/node/api";
const cookies = useCookies();
This hook returns a request header.
import { useHeader } from "sst/node/api";
const header = useHeader("Authorization");
This hook returns all request headers.
import { useHeaders } from "sst/node/api";
const headers = useHeaders();
This hook returns the request form data.
import { useFormData } from "sst/node/api";
const data = useFormData();
This hook returns the request form value.
import { useFormValue } from "sst/node/api";
const name = useFormValue("name");
This hook returns a request query parameter.
import { useQueryParam } from "sst/node/api";
const name = useQueryParam("name");
This hook returns all request query parameters.
import { useQueryParams } from "sst/node/api";
const params = useQueryParams();
This hook returns a request path parameter.
import { usePathParam } from "sst/node/api";
const id = usePathParam("id");
This hook returns all request query parameters.
import { usePathParams } from "sst/node/api";
const params = usePathParams();