Response body

  • A Response body defines the information sent by the Langstack API application to the endpoint in the network (i.e., client).

  • A Response body contains the details of the API's response to a request.

  • The user can access the Response body through the Response variable, which has the response body(s) defined under the Response body section.

  • The Response variable holds the payload for the response (i.e., the actual message or data sent in the response).

  • A Request body and Response body share similarities in the structure and the UI layout, except that the Response body has an additional field of Response Code. The sections defining the Response body are as follows:

    1. Response body Name: The name of the response.

    2. Content Type: The content type is a data type.

    3. Response Code: This is a numerical value associated with the Response to represent the status of the Response. For example, if the API had processed the Request received correctly and with no errors, the most commonly used Response code would be 200. The Response Code is not standardized as the user is not obligated to use a specific response code for a Response status, and the user can choose to assign any code to any response type in the Response body. However, it is recommended that the user assigns the Response Code wisely and assigns the most popularly used codes instead of just any code. This is because different platforms may have their interpretation of response codes, and assigning any response code may cause unwanted results. To choose the suitable Response code, ensure that the clients using the API can process the Response code as assigned. Another approach is to use one response code and include in the body of the response the status of the response as one of the fields in your response.

    4. Character Set: The character set defines the content that the response body is sent with.

    5. Description: The description field lets the user describe the purpose of the response body, and this text will be visible in the API documentation.

    6. Copy Sample from Entity: When a user selects an existing entity from the Copy Sample field, it copies a JSON sample for the entity into the Sample Box.

    7. Sample Box: The Sample Box should contain a sample of the response that matches the Content-Type, for example, if the content type is application/json the user needs to provide a JSON sample which can be entered directly or copied from an existing entity by using the dropdown โ€œCopy Sample from Entityโ€. The sample should be similar to the expected Json to respond with.

  • Users may define multiple response bodies in an API to handle different Content Types. However, only one of the response bodies defined will contain the response data to be sent to the client. For example, suppose a request is received in XML or JSON format. In that case, the relevant response bodies may be defined i.e. a response body may be defined to send an XML response, and another response body may be defined to send a JSON response, but for one request, only one of them will send the response. Generally, in practice, the request body content type or the Accept header received may influence which response body content type to respond with.

Last updated