All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.client.SphereRequest Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.client;

import io.sphere.sdk.http.HttpResponse;

/**
 An argument for a sphere client to execute an HTTP API call on the level of one SPHERE.IO project.

 

Typical workflow: A client executes {@link #httpRequestIntent()} and creates a future of an http response. When the future redeems the client uses the http response and passes it as argument to {@link #canDeserialize(HttpResponse)}. If the call results in true, the client applies {@link #deserialize(HttpResponse)} to transform the http response into T.

It is intented that this class is immutable, so that every method can be used in a pure functional way. @param the type which is returned in a successful http request. */ public interface SphereRequest { /** Takes an http response and maps it into a Java object of type T. Before calling this method, check with {@link #canDeserialize(HttpResponse)} if the response can be consumed. @return the deserialized object, it should not be null @param httpResponse the http response of SPHERE.IO */ T deserialize(final HttpResponse httpResponse); /** Provides an http request intent, this does not include the execution of it. @return http request intent */ HttpRequestIntent httpRequestIntent(); /** Checks if the response can be handled by {@link #deserialize(HttpResponse)}. Use case 1: A http response returns 404 and the this {@link SphereRequest} can handle this error by returning an empty optional, an empty list or throwing a domain specific exception. @param httpResponse the http response which shall be transformed @return true if the http response can be consumed, false otherwise */ default boolean canDeserialize(final HttpResponse httpResponse) { return httpResponse.hasSuccessResponseCode() && httpResponse.getResponseBody() != null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy