Methods for HTTP Functions

Each HTTP function contains a method definition that is used to call the corresponding custom site API.

The method is defined in the function declaration:

Copy

HTTP functions support the following method declarations:

Methods

get

Calls your custom site API using the HTTP GET method.

Usually, GET methods are used only to retrieve a resource. If the resource is found, your function should respond with a 200 (OK) status code and the requested resource.

Learn more about get HTTP functions.

Example: Create a GET HTTP function that queries a collection to find items based on the path of the request

Copy

post

Calls your custom site API using the HTTP POST method.

Usually, POST methods are used to create a new resource. If the resource is successfully created, your function should respond with a 201 (Created) status code and a reference to the created resource.

Learn more about post HTTP functions.

Example: Create a POST HTTP function that inserts an item from the request's body into a collection

Copy

put

Calls your custom site API using the HTTP PUT method.

Usually, PUT methods are used to update a resource. If the resource is successfully updated, your function should respond with a 200 (OK) status code. If the resource didn't exist so it was created, your function should respond with a 201 (Created) status code.

Learn more about put HTTP functions.

Example: Create a PUT HTTP function that updates an item from the request's body in a collection

Copy

delete

Calls your custom site API using the HTTP DELETE method.

Usually, DELETE methods are used to delete a resource. If the resource is successfully deleted, your function should respond with a 200 (OK) status code.

Learn more about delete HTTP functions.

Example: Create a DELETE HTTP function that deletes an item from a collection based on the path of the request

Copy

use

Calls your custom site API using any HTTP method, unless there is another function with the same name defined for that specific HTTP method.

For example, if you create 2 HTTP functions, called get_myFunction and use_myFunction, GET calls to myFunction will be handled by get_myFunction, but POST, PUT, and DELETE calls to myFunction will be handled by use_myFunction.

Learn more about use HTTP functions.

See also

Was this helpful?
Yes
No