-
-
Notifications
You must be signed in to change notification settings - Fork 0
Responses
Almost all endpoints share the same base body response and this is represented by the BaseResponse model.
You can access the response data using the data property.
val artworkService = ArtworkService()
val response = artworkService.getItems(limit = 2)
val data = response.dataDepending on the endpoint, you will get a list of objects or a single object.
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.paginationFor endpoints that return a single item, it will be null.
When the endpoint returns a list of items, an empty list will be returned.
When the endpoint is intended to return a single item, an ItemNotFoundException will be thrown.
Only the Artwork's manifest endpoint returns a different response. It returns a ArtworkManifest directly.
When the manifest cannot be found, an ItemNotFoundException will be thrown.
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.
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.