Handler

Traditional HTTP frameworks expose endpoints. Handlers are Teo's HTTP endpoints.

The URL path of the handler

When working with HTTP requests, the requests are mapped into handlers with predefined rules.

When Teo's frontend packages are building a request url, they use a form of /{server path prefix}/{namespacePaths}/{ModelName}/{actionName}. For example, to access findMany on User, we request this url: /User/findMany.

Builtin auto-synthesized handlers

The builtin handlers supported by Teo are:

  • findUnique find a unique object
  • findMany find many objects
  • findFirst find one object
  • create create a new object
  • update update an existing object
  • upsert create an existing object if it doesn't exist
  • copy copy an existing object into a new one
  • delete delete an existing object
  • createMany create many objects
  • updateMany update many objects
  • copyMany create many objects by copying
  • deleteMany delete many objects
  • count count matched objects
  • aggregate view statistics data on this model
  • groupBy view grouped statistics data on this model

Disabling auto-synthesized handlers

This feature is currently working in progress. We used to have this feature, but when we refactored our core in version 0.0.58, this feature is missing from the framework. We will add back this feature soon and update this documentation here.

Custom handler

Besides auto-synthesized handlers, developers can declare custom handlers with the declare handler syntax.

declare handler myHandler(MyInput): MyOutput

Non-api handler

Some of the handlers may return HTML pages, images or something else which should not be exposed into Teo query client. Use the nonapi keyword to declare handlers of these types.

@map(.get, "/")
declare nonapi handler myHomePage(): Any

Custom handler group

Handlers can be declared directly in namespaces and models. It's great to group APIs together. Use declare handler group to declare a handler group to place handlers of the same group. The handler group takes a part in the request URL just like a model.

declare handler group Auth {
  declare handler myAuth(MyAuthInput): MyAuthOutput
}

Handler implementation

To implement custom handlers, use server APIs. See: