Skip to content

Responses

Peter Araujo edited this page Jul 28, 2024 · 1 revision

Body responses

General responses

Almost all endpoints share the same base body response and this is represented by the BaseResponse model.

Data

You can access the response data using the data property.

val artworkService = ArtworkService()

val response = artworkService.getItems(limit = 2)

val data = response.data

Depending on the endpoint, you will get a list of objects or a single object.

Pagination

Item list

For endpoints that return a list of items, pagination is expected to be available.

val artworkService = ArtworkService()

val response = artworkService.getItems(limit = 2)

val pagination = response.pagination
Single items

For endpoints that return a single item, it will be null.

Not founds

Item list

When the endpoint returns a list of items, an empty list will be returned.

Single items

When the endpoint is intended to return a single item, an ItemNotFoundException will be thrown.

Other responses

Artwork manifest

Only the Artwork's manifest endpoint returns a different response. It returns a ArtworkManifest directly.

Not founds

When the manifest cannot be found, an ItemNotFoundException will be thrown.

HTTP responses

You can obtain the full HttpResponse adding "AsHttpResponse" to the endpoint function. For example:

val artworkService = ArtworkService()

val response = artworkService.getItemsAsHttpResponse(limit = 2)

Note: Exceptions are thrown from the client, so you can handle them the same way as the parsed responses.

Converting raw body to model

If you need the body as a model object, you will need to convert the response body to object. For example:

val artworkService = ArtworkService()

val response = artworkService.getItemsAsHttpResponse(limit = 2)

val bodyAsModel = ArticApiClient.defaultJson.decodeFromString(
        deserializer = BaseResponse.serializer(Artwork.serializer()),
        string = response.bodyAsText()
    )

You will need a Json to deserialize the response. ArticApiClient provides its default Json (ArticApiClient.defaultJson), so can use it as needed.

Clone this wiki locally