Skip to content

Latest commit

 

History

History
83 lines (54 loc) · 2.01 KB

operations.md

File metadata and controls

83 lines (54 loc) · 2.01 KB
id title
operations
Operations

Operations

Operations describe service endpoints and consist of an operation name, parameters, and return type.

Operations are declared using the op keyword:

op ping(): void;

Parameters

The operation's parameters describe a model, so anything you can do in a model you can do in a parameter list as well, including using the spread operator:

op feedDog(...CommonParams, name: string): void;

Return type

Often an endpoint returns one of any number of models. For example, there might be a return type for when an item is found, and a return type for when an item isn't found. Unions are used to describe this pattern:

model DogNotFound {
  error: "Not Found";
}

op getDog(name: string): Dog | DogNotFound;

Reuse operations

Operation signatures can be reused using the is keyword. Given an operation

op Delete(id: string): void;

its signature can be reused like this:

op deletePet is Delete;

This means that deletePet will have the same parameters, return type and decorators as the Delete operation.

This pattern is most commonly used in combination with operation templates

Operations templates

See templates for details on templates.

op ReadResource<T>(id: string): T;

The operation template can then be referenced via is:

op readPet is ReadResource<Pet>;

Referencing model properties

Model properties can be referenced using the . operator for identifiers.

alias PetName = Pet.name;

Meta type references

Some operation meta types can be referenced using ::

Name Example Description
parameters readPet::parameters Reference the parameters model expression
returnType readPet::returnType Reference the operation return type