Skip to content

HTTP Endpoints

Derek Clarkson edited this page Nov 19, 2022 · 2 revisions

To response to RESTful API requests Voodoo needs to be configured with HTTP Endpoints. These need 3 things:

  • The HTTP method of the incoming request. ie. GET, POST, etc.
  • The path of the incoming request. ie. /login, /accounts/list, etc.
  • And finally a response to return which specifies the HTTP status code, body, etc.

A simple example might look like this in an XCTest:

Endpoint(.GET, "/config", response: .json(["featureFlag": true]))

or in a YAML config file:

http:
  api: get /config
  response:
    status: 200
    body:
      json:
        featureFlag: true      

Path parameters

Apart from fixed paths such as /login and /accounts, Voodoo can also extract arguments from REST like paths.

For example, if you want to query user's account using /accounts/users/1234 where 1234 is the user's employee ID, then you can specify the path as /accounts/users/:employeeId and Voodoo will automatically map any incoming request to the /accounts/users/* path, extracting the employee ID into a field which it then makes available to dynamic responses.

Responses

Please see the Endpoint responses document for an outline of how to specify the response for an endpoint.

Clone this wiki locally