Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Services

It is reasonable to have an API endpoint that doesn’t quite fit into a Model’s namespace, or that needs to interact with multiple Models and Data Sources.

To accomodate this use case, Cloesce allows you to define a Model that has no data associated with it, and only serves as a namespace for API methods. This is commonly referred to as a “Service”.

Defining a Service

A service is a model block with empty braces:

model FooService {}

api FooService {
    get do_foo() -> string
}

The implementation is the same as for any other model:

import * as clo from "@cloesce/backend.js";

const FooService = clo.FooService.impl({
  do_foo() {
    return "foo";
  },
});