Skip to main content
Version: Latest (0.56.x)

Operations

Operations are essentially service endpoints, characterized by an operation name, parameters, and a return type.

You can declare operations using the op keyword:

op ping(): void;

Parameters

The parameters of an operation represent a model. Therefore, you can perform any action with parameters that you can with a model, including the use of the spread operator:

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

Return type

Frequently, an endpoint may return one of several possible models. For instance, there could be a return type for when an item is located, and another for when it isn't. Unions are employed to express this scenario:

model DogNotFound {
error: "Not Found";
}

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

Reusing operations

You can reuse operation signatures with the is keyword. For example, given an operation

op Delete(id: string): void;

You can reuse its signature like so:

op deletePet is Delete;

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

This practice is typically used in conjunction with operation templates

Operation templates

For more information on templates, see templates.

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

You can reference the operation template using is:

op readPet is ReadResource<Pet>;

Referencing model properties

You can reference model properties using the . operator for identifiers.

alias PetName = Pet.name;

Meta type references

Certain operation meta types can be referenced using ::

NameExampleDescription
parametersreadPet::parametersReferences the parameters model expression
returnTypereadPet::returnTypeReferences the operation return type