Add an operation

In this topic, you learn how to add an operation to an API.

In each operation, you define a method to interact with the data of the API. You can define multiple operations with different methods and parameters for requests.

Prerequisites

Procedure

  1. In the Operations tab, select + to add an operation.

  2. In Path, enter a slash and a name for this method, for example, /getCharactersPerPlanet.

    Allow path parameters in the endpoint, for example, /path/(id)/(loc). These parameters can be fetched in the script itself by doing:

    const id_param = req.params.id;
    const loc_param = req.params.loc;

    In Method, select a method from the list, for example GET:

    GET

    Read and retrieve data from the resource.

    PUT

    Update existing data in the resource.

    POST

    Add new data to the resource.

    DELETE

    Delete data from the resource.

    HEAD

    Read and retrieve data without the response body. Unlike GET, HEAD retrieves the response header only.

    OPTIONS

    Read and retrieve all operations and content types that are available without retrieving specific data.

    PATCH

    Apply partial changes to an operation. Unlike PUT, PATCH changes only part of the data instead of replacing it entirely.

  3. Select the icon in Server Script and select the server script you want to call from the list.

  4. In Restrict Access, you can define which role or roles can access the API.

    You can only restrict access if you have defined roles before with the Role service.
  5. Enter a short Summary and a longer Description to provide context information about the operation.

  6. In Tags, enter keywords that describe the resource.

  7. Activate any of the following:

    Trace Operations

    Trace request you or others make to the API in API Trace.

    Save Request Body

    When you trace operations, the request details are traced, too.

    Send Credentials (cookie)

    Send cookie information with the API call.

    Use Example Data

    Use example data to run an unfinished API in the App Designer. Example data is not traced in API Trace or API Client.

  8. Select Save.

Result

  • You have added an operation with a method.