Class Tm1Request<T>
java.lang.Object
io.skipcheck.tm1.client.Tm1Request<T>
- Type Parameters:
T- the type the response is read as: an entity or value for a single response, the item type for a collection,Stringfor text, orVoidfor no content
One TM1 REST call, described but not sent: the method, path, query, headers and body,
and how to read the response.
Every service method is built on one of these. The same request can be sent on its own
(the service's ordinary methods do that) or added to a $batch, so anything the
client can do one request at a time, it can also batch. Requests are immutable.
// A cube's name, read as plain JSON
Tm1Request<JsonNode> cube = Tm1Request.get(ODataPath.of("Cubes").key("Sales"), ODataQuery.none().select("Name"),
JsonNode.class);
// An action with no answer
Tm1Request<Void> reserve = Tm1Request.post(ODataPath.of("Cubes").key("Sales").action("tm1.Reserve"), Map.of(),
Void.class);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA body of raw bytes rather than JSON: seeput(ODataPath, Publisher).static enumHow the response body is read. -
Method Summary
Modifier and TypeMethodDescription@Nullable Objectbody()The body, serialized as JSON when sent, ornullfor none.static Tm1Request<DataBuffer> GETof raw bytes, such as a document'sContent, streamed withTm1Session.stream.static Tm1Request<Void> DELETE.static <T> Tm1Request<T> get(ODataPath path, ODataQuery query, Class<T> type) GETof one entity or value.headers()The headers this request adds, in the order they were added.A copy sent withIf-Match: etag, failing with 412 if the entity has changed since.booleanWhether sending this twice has the same effect as sending it once: GET, PUT and DELETE are; POST (process runs, cell writes, creates) and PATCH aren't.static <T> Tm1Request<T> list(ODataPath path, ODataQuery query, Class<T> itemType) GETof a collection, read item by item asitemType.method()The HTTP method.static Tm1Request<Void> PATCH: change the properties inbody, leaving the rest as they are.path()The resource path, relative to the service root.static <T> Tm1Request<T> POST: create an entity, or invoke an action.static <T> Tm1Request<T> POSTwhose response is a collection, read item by item asitemType: an action returningCollection(...), such astm1.CheckRules.static Tm1Request<Void> put(ODataPath path, org.reactivestreams.Publisher<DataBuffer> content) PUTof raw bytes, asapplication/octet-stream, such as a document'sContent.query()The query options.The encoded path and query relative to the service root, e.g.What this request needs the server to define, if anything.requires(Tm1Capability capability) A copy that's only sent if the server definescapability: before sending, the session checks the server's$metadataand otherwise fails withTm1UnsupportedOperationException, without calling the server.response()How the response body is read.static Tm1Request<String> GETof plain text, such asConfiguration/ProductVersion/$value.timeout()This request's own timeout, if it has one; otherwise the session's applies.toString()METHOD relative-uri, unencoded, for logs.type()The class the response, or each item of a collection, is read as.withHeader(String name, String value) A copy with a header added or replaced, such asIf-Match.withQuery(ODataQuery query) A copy with these query options instead.withTimeout(Duration timeout) A copy that may gotimeoutwithout receiving any data before it fails, instead of the session's request timeout.
-
Method Details
-
get
GETof one entity or value.- Type Parameters:
T- the type the response is read as- Parameters:
path- the resource pathquery- the query optionstype- the class the response is read as- Returns:
- the request
-
list
GETof a collection, read item by item asitemType.- Type Parameters:
T- the type each item is read as- Parameters:
path- the collection's pathquery- the query optionsitemType- the class each item is read as- Returns:
- the request
-
bytes
GETof raw bytes, such as a document'sContent, streamed withTm1Session.stream. Each buffer is the subscriber's to release (DataBufferUtils.release), or to hand on to something that does, such asDataBufferUtils.write.- Parameters:
path- the resource path- Returns:
- the request
-
put
public static Tm1Request<Void> put(ODataPath path, org.reactivestreams.Publisher<DataBuffer> content) PUTof raw bytes, asapplication/octet-stream, such as a document'sContent. TM1 (11.8) refuses a chunked body (400, with no message), so the bytes are gathered and sent with theirContent-Length: the whole content is held in memory while it's sent. If the session has to log in again, the request is sent once more andcontentsubscribed again, so it should be one that can be:DataBufferUtils.readof a file is.- Parameters:
path- the resource pathcontent- the bytes- Returns:
- the request
-
text
GETof plain text, such asConfiguration/ProductVersion/$value.- Parameters:
path- the resource path- Returns:
- the request
-
postList
POSTwhose response is a collection, read item by item asitemType: an action returningCollection(...), such astm1.CheckRules.- Type Parameters:
T- the type each item is read as- Parameters:
path- the action's pathbody- the parameters, written as JSONitemType- the class each item is read as- Returns:
- the request
-
post
POST: create an entity, or invoke an action. Actions always get a JSON body (an empty object if there are no parameters), since TM1 refuses an action without a JSON content type. WithVoid.classthe response is ignored.- Type Parameters:
T- the type the response is read as- Parameters:
path- the collection or action pathbody- the entity or action parameters, ornullfor an empty objecttype- the class the response is read as:Void.classto ignore it,String.classto read it as text- Returns:
- the request
-
patch
PATCH: change the properties inbody, leaving the rest as they are.- Parameters:
path- the entity's pathbody- the properties to change- Returns:
- the request
-
delete
DELETE.- Parameters:
path- the path of the entity to delete- Returns:
- the request
-
withQuery
A copy with these query options instead.- Parameters:
query- the query options- Returns:
- the copy
-
withHeader
A copy with a header added or replaced, such asIf-Match.- Parameters:
name- the header namevalue- the header value- Returns:
- the copy
-
withTimeout
A copy that may gotimeoutwithout receiving any data before it fails, instead of the session's request timeout. For calls TM1 only answers when the work is done, such as a long process run.- Parameters:
timeout- the longest wait for data; must be positive- Returns:
- the copy
-
requires
A copy that's only sent if the server definescapability: before sending, the session checks the server's$metadataand otherwise fails withTm1UnsupportedOperationException, without calling the server. Service methods for newer endpoints declare it.- Parameters:
capability- what the request needs the server to define- Returns:
- the copy
-
requirement
What this request needs the server to define, if anything.- Returns:
- the capability, or empty
-
ifMatch
A copy sent withIf-Match: etag, failing with 412 if the entity has changed since.- Parameters:
etag- the entity's ETag- Returns:
- the copy
-
method
-
path
-
query
-
headers
-
body
The body, serialized as JSON when sent, ornullfor none.- Returns:
- the body, or
null
-
response
-
type
-
timeout
-
isIdempotent
public boolean isIdempotent()Whether sending this twice has the same effect as sending it once: GET, PUT and DELETE are; POST (process runs, cell writes, creates) and PATCH aren't. The client never retries a non-idempotent request by itself.- Returns:
truefor GET, PUT, DELETE and HEAD
-
relativeUri
The encoded path and query relative to the service root, e.g.Cubes('Sales')?$select=Name.- Returns:
- the relative URI
-
toString
-