glitr/service

This module helps you create standard CRUD services routes

Types

The RouteService type
Contains the data necessary to build the CRUD routes. Note that all data transmission will be done via JSON objects.

pub type RouteService(base_type, upsert_type) {
  RouteService(
    root_path: List(String),
    base: Option(
      #(
        fn(base_type) -> json.Json,
        fn(dynamic.Dynamic) ->
          Result(base_type, List(dynamic.DecodeError)),
      ),
    ),
    upsert: Option(
      #(
        fn(upsert_type) -> json.Json,
        fn(dynamic.Dynamic) ->
          Result(upsert_type, List(dynamic.DecodeError)),
      ),
    ),
  )
}

Constructors

  • RouteService(
      root_path: List(String),
      base: Option(
        #(
          fn(base_type) -> json.Json,
          fn(dynamic.Dynamic) ->
            Result(base_type, List(dynamic.DecodeError)),
        ),
      ),
      upsert: Option(
        #(
          fn(upsert_type) -> json.Json,
          fn(dynamic.Dynamic) ->
            Result(upsert_type, List(dynamic.DecodeError)),
        ),
      ),
    )

Functions

pub fn create_route(
  service: RouteService(a, b),
) -> Result(Route(Nil, Nil, b, a), GlitrError)

Generate a create route associated with a service

pub fn delete_route(
  service: RouteService(a, b),
) -> Result(Route(String, Nil, Nil, String), GlitrError)

Generate a delete route associated with a service
Note that the return is the id of the deleted instance

pub fn get_all_route(
  service: RouteService(a, b),
) -> Result(Route(Nil, Nil, Nil, List(a)), GlitrError)

Generate a get-all route associated with a service

pub fn get_route(
  service: RouteService(a, b),
) -> Result(Route(String, Nil, Nil, a), GlitrError)

Generate a get route associated with a service

pub fn new() -> RouteService(a, b)

Create a new empty service
The base and upsert types will have to be specified !

pub fn update_route(
  service: RouteService(a, b),
) -> Result(Route(String, Nil, b, a), GlitrError)

Generate a update route associated with a service

pub fn with_base_type(
  service: RouteService(a, b),
  base_encoder: fn(c) -> Json,
  base_decoder: fn(Dynamic) -> Result(c, List(DecodeError)),
) -> RouteService(c, b)

Specify the base type of a service by providing a JSON encoder & decoder
The base type of a service represent the type of object your service is associated with

pub fn with_base_type_converter(
  service: RouteService(a, b),
  converter: Converter(c),
) -> RouteService(c, b)

Specify the base type of a service by providing a glitr_convert type
The base type of a service represent the type of object your service is associated with

pub fn with_root_path(
  service: RouteService(a, b),
  root_path: List(String),
) -> RouteService(a, b)

Change the root path of a service

pub fn with_upsert_type(
  service: RouteService(a, b),
  upsert_encoder: fn(c) -> Json,
  upsert_decoder: fn(Dynamic) -> Result(c, List(DecodeError)),
) -> RouteService(a, c)

Specify the upsert type of a service by providing a JSON encoder & decoder
The upsert type of a service represent the type used to create or update objects of your service

pub fn with_upsert_type_converter(
  service: RouteService(a, b),
  converter: Converter(c),
) -> RouteService(a, c)

Specify the upsert type of a service by providing a glitr_convert type
The upsert type of a service represent the type used to create or update objects of your service

Search Document