Interfaces & Services
The interfaces
property in blocklet.yml
is the primary mechanism for a blocklet to expose itself to the world. It defines all the entry points, such as web UIs, APIs, or other accessible endpoints. Each interface can be configured with specific routing, port mapping, and built-in services like authentication to secure its resources.
This section details the configuration of the interfaces
array and its associated properties, including how to attach and configure services.
The interfaces
Array#
A blocklet can define multiple interfaces in this array. Each object in the array represents a distinct entry point.
Interface Properties#
Each interface object is defined by the following properties, derived from the interfaceSchema
:
Property | Type | Description |
---|---|---|
| String | Required. The type of interface. Valid values are |
| String | Required. A unique, human-readable name for the interface (e.g., |
| String | The internal path within the blocklet that this interface serves. Defaults to |
| String | The URL prefix where this interface is mounted. A value of |
| String or Object | Specifies port mapping. Can be a string referencing an environment variable (e.g., |
| String | The protocol used by the interface. Valid values are |
| Number | The port inside the container to expose when using Docker. |
| String | Binds the interface to a specific host IP address (IPv4 or IPv6). |
| String | Defines how requests are handled. |
| Array | An array of path prefixes (e.g., |
| Array | An array of built-in services to apply to this interface. See the Configuring Services section below. |
| Array | An array defining specific API endpoints exposed by this interface, complete with metadata. See Endpoint Properties. |
| Array | An array of strings used to group pages, which can be utilized by the user interface for organizational purposes (e.g., creating menu sections). |
Endpoint Properties#
The endpoints
array provides metadata for specific API endpoints, which can be used by other blocklets or tools for service discovery. This is defined by the endpointSchema
.
Property | Type | Description |
---|---|---|
| String | Required. A string identifying the endpoint's purpose (e.g., |
| String | Required. The path for this specific endpoint, relative to the interface's |
| Object | An object containing additional metadata, such as |
Example: Basic Web and API Interfaces#
interfaces:
- name: primary
type: web
path: /
prefix: '*'
port: BLOCKLET_PORT
protocol: http
cacheable:
- /assets
- /static
- name: api
type: web
path: /api/v1
prefix: /api/v1
port: BLOCKLET_PORT
protocol: http
endpoints:
- type: health-check
path: /healthz
- type: get-user
path: /user/:did
meta:
payable: true
Configuring Services#
The services
array within an interface allows you to enable and configure built-in functionalities provided by the ABT Node environment. Each service object requires a name
and a config
object.
services:
- name: auth
config:
# ... auth service configuration here
The most commonly used service is auth
for access control.
The auth
Service#
The auth
service protects an interface by enforcing authentication and authorization rules. Its configuration is defined by the authConfigSchema
.
Config Property | Type | Description |
---|---|---|
| String | Defines who can access the interface. Valid options: |
| Boolean | If |
| Boolean | If |
| Boolean | If |
| Array | An array of URL paths or patterns that will bypass the authentication check. |
| Array | Deprecated. Previously used to request specific user profile fields. |
Example: Interface with Authentication#
This example configures a web interface that is only accessible to the node owner and any users they have invited. The login page itself (/login
) is excluded from the authentication check.
interfaces:
- name: admin-dashboard
type: web
path: /
prefix: '*'
port: BLOCKLET_PORT
protocol: http
services:
- name: auth
config:
whoCanAccess: invited
blockUnauthenticated: true
blockUnauthorized: true
ignoreUrls:
- /login
By correctly defining interfaces and services, you can control exactly how your blocklet is exposed and secured. You are now ready to learn how to build more complex applications by composing multiple blocklets together.
Next: Composition (Components).