# Module type `Rest.SERVICE`

The `SERVICE`

interface has to be implemented by a CRUD service that drives the resource with its business logic.

`val find : string -> t option Lwt.t`

`find id`

returns`t`

if it is found.

`val search : ?filter:string -> ?sort:[ `Desc | `Asc ] -> ?limit:int -> ?offset:int -> unit -> (t list * int) Lwt.t`

`search ?filter ?sort ?limit ?offset ()`

returns a subset of the whole collection of`t`

. The returned tuple consist of the resulting subset and the total number of`t`

stored.`filter`

is an optional keyword that is used to apply a filter. Only items are shown where`t`

contains`filter`

in some form. The exact implementation is open, but`filter`

should be used as general search keyword.`sort`

describes whether the result is sorted in descending or ascending order. The field that is sorted by and the default value are defined by the implementation for security reason.`limit`

is the number of`t`

in the resulting subset. A sane default is defined by the implementation.`offset`

is the number of`t`

skipped before the resulting subset. A sane default is defined by the implementation.

`val insert : t -> (t, string) Result.t Lwt.t`

`insert t`

inserts`t`

and returns an error message that can be shown to the user if it fails.

`val update : string -> t -> (t, string) Stdlib.result Lwt.t`

`update id t`

updates the t that is found using its`id`

with`t`

and returns an error message that can be shown to the user if it fails.This function is similar to

`insert`

and it overwrites an existing`t`

.

`val delete : t -> (unit, string) Stdlib.result Lwt.t`

`delete t`

deletes`t`

and returns an error message that can be shown to the user if it fails.