RestEntity

class RestEntity<T, I>(resource: Resource<T, I>, initialId: I, contentType: String, remote: Request) : EntityRepository<T, I>

provides crud-functions for REST-API to a defined Resource

Parameters

resource

definition of the Resource

initialId

id to compare a given resource for differentiation of adding or updating

contentType

to be used by the REST-API

remote

base Request to be used by all subsequent requests. Use it to configure authentication, etc.

Constructors

Link copied to clipboard
fun <T, I> RestEntity(resource: Resource<T, I>, initialId: I, contentType: String, remote: Request)

Functions

Link copied to clipboard
open suspend override fun addOrUpdate(entity: T): T

sends a post-(for add) or a put-(for update) request to remote/{id} with the serialized entity in it's body. The initialId is used to determine if it should add or updated.

Link copied to clipboard
open suspend override fun delete(entity: T)

deletes an entity by a delete-request to resource.url/{id}

Link copied to clipboard
open suspend override fun load(id: I): T

loads an entity by a get request to resource/{id}

Properties

Link copied to clipboard
val contentType: String
Link copied to clipboard
val initialId: I