This is an in-development version. Grow with us! 🎉

APIs

Introduction

In Fustak, each API is defined using two files: a .toml configuration file and a .js request handler file. The .toml file is responsible for configuring the API, while the .js file handles the requests for the API.

Default API Configuration

To set default configurations for your APIs, you can create a default API configuration file prefixed with _default, such as _default.api.toml. This default configuration can be overriden for individual APIs.

Here is an example of the default page configuration:

[api.default]
file = "../_default.api.toml"

API Builder Configuration

The configuration includes the following settings:

  • − active: A boolean value indicating whether the API is active (true) or not (false).
  • − service: The name of the API, identified as counter-service. This name provides a unique identifier for the API.
  • − api: The path to the JavaScript file (counter.add.api.js) containing the logic for the API. The file likely includes code responsible for handling the functionality of the API.
  • − method: The HTTP method used by the API, specified as PUT. The PUT method is typically used to update or create a resource on the server.
  • − path: The endpoint path for the API, set to /counter. This means that the API will be accessible at the /api/counter endpoint. When a client sends a request to this endpoint, the logic defined in the JavaScript file will be executed.
[api.builder]
active = true
service = "counter-service"
api = "counter.add.api.js"
method = "PUT"
path = "/counter"

API Builder Headers Configuration

The API builder headers configuration allows you to configure the headers for the webpage's response.

[api.builder.headers]
Access-Control-Allow-Origin = "*"
Access-Control-Allow-Credentials = "true"

API Deployment

To deploy an API, you can use the following command:

fustak apis [PATH]

The fustak apis command deploys all the apis.