Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class CloudHttp
- Object
- CloudHttp
Helpers shared by the REST clients: JSON bodies and the response handlers.
UTF-8 conversion is
com.codename1.util.StringUtil, URL encoding
com.codename1.io.Util#encodeUriComponent(String) and JSON member reads
com.codename1.mapping.JsonValues.Nested types
interface CloudHttp.Reauthenticator | What #retryOn401(CloudHttpTransport.Handler, Reauthenticator) does when a request is refused with 401: refresh the credentials, then send the same request again without another retry. |
Methods
Inherited methods
Method details
toJson
public static byte[] toJson(Object value)Serializes a map or list to JSON bytes.
Parameters
valueObject- a
MaporList
Returns
the UTF-8 JSON
parseJson
public static Map<String, Object> parseJson(byte[] body)Parses a JSON response. A top level array is returned under the key
root.Parameters
bodybyte[]- the response body
Returns
the parsed map, empty when the body is empty or invalid
parseJsonArray
public static List<Map<String, Object>> parseJsonArray(byte[] body)Parses a JSON array response into a list of objects.
Parameters
bodybyte[]- the response body
Returns
the rows, empty when the body holds no objects
failed
public static boolean failed(AsyncResource<?> out, int status, byte[] body)Completes
out with an error when status is not a 2xx code.Parameters
outAsyncResource<?>- the result to fail
statusint- the HTTP status
bodybyte[]- the response body
Returns
true when the status was an error and
out was failedjsonHandler
public static CloudHttpTransport.Handler jsonHandler(AsyncResource<Map<String, Object>> out)A handler that completes
out with the parsed JSON object of a 2xx response.Parameters
outAsyncResource<Map<String, Object>>- the result
Returns
the handler
bytesHandler
public static CloudHttpTransport.Handler bytesHandler(AsyncResource<byte[]> out)A handler that completes
out with the body of a 2xx response.Parameters
outAsyncResource<byte[]>- the result
Returns
the handler
doneHandler
public static CloudHttpTransport.Handler doneHandler(AsyncResource<Boolean> out)A handler that completes
out with true on a 2xx response.Parameters
outAsyncResource<Boolean>- the result
Returns
the handler
rowsHandler
public static CloudHttpTransport.Handler rowsHandler(AsyncResource<List<Map<String, Object>>> out)A handler that completes
out with the rows of a 2xx JSON array response.Parameters
outAsyncResource<List<Map<String, Object>>>- the result
Returns
the handler
retryOn401
public static CloudHttpTransport.Handler retryOn401(CloudHttpTransport.Handler handler, CloudHttp.Reauthenticator auth)Wraps a handler so that a 401 response refreshes the credentials and
resends the request once. Any other status, and a 401 whose refresh
fails, reaches
handler unchanged.Parameters
handlerCloudHttpTransport.Handler- the handler of the original request
authCloudHttp.Reauthenticator- refreshes the credentials and resends
Returns
the wrapping handler