-
- All Implemented Interfaces:
public final class JSONKtorFunctionsKt
-
-
Field Summary
Fields Modifier and Type Field Description private final static ContentTypeapplicationJSONprivate final static StringapplicationJSONString
-
Method Summary
Modifier and Type Method Description final ContentTypegetApplicationJSON()The application/jsoncontent typefinal StringgetApplicationJSONString()The application/jsoncontent type as a stringfinal static Unitkjson(Configuration $self, ContentType contentType, Function1<JSONConfig, Unit> block)Register the kjsoncontent converter, configuring theJSONConfigwith a lambda.final static Unitkjson(Configuration $self, JSONConfig config, ContentType contentType)Register the kjsoncontent converter, supplying aJSONConfig.final static Unitkjson(ContentNegotiation.Config $self, ContentType contentType, Function1<JSONConfig, Unit> block)Register the kjsonclient content converter, configuring theJSONConfigwith a lambda.final static Unitkjson(ContentNegotiation.Config $self, JSONConfig config, ContentType contentType)Register the kjsonclient content converter, supplying aJSONConfig.final static HeaderscontentTypeJSON()Get a Headers containing a Content-Typeofapplication/json.final static HeaderscontentTypeJSON(Charset charset)Get a Headers containing a Content-Typeofapplication/jsonwith the specified Charset.final static KtorByteChannelOutputchannelOutput(ByteWriteChannel channel, Charset charset)Create a KtorByteChannelOutput (convenience function). final static OutgoingContentcreateStreamedJSONContent(Object value, ContentType contentType, Charset charset, JSONConfig config)Create an OutgoingContent to stream JSON output. final static UnitrespondStream(ApplicationCall $self, ContentType contentType, HttpStatusCode status, Long contentLength, Charset charset, SuspendFunction1<SuspendFunction1<Character, Unit>, Unit> producer)Respond to a call using streamed data. final static <T extends Any> UnitreceiveStreamJSON(HttpClient $self, String urlString, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)Make a client call, receiving the response as a stream. final static <T extends Any> UnitreceiveStreamJSON(HttpClient $self, KType type, String urlString, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)Make a client call, receiving the response as a stream. final static <T extends Any> UnitreceiveStreamJSON(HttpClient $self, Url url, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)Make a client call, receiving the response as a stream. final static <T extends Any> UnitreceiveStreamJSON(HttpClient $self, KType type, Url url, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)Make a client call, receiving the response as a stream. final static <T extends Any> UnitexecuteStreamJSON(HttpClient $self, KType type, HttpRequestBuilder requestBuilder, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)Make a client call with the parameters supplied in a HttpRequestBuilder, receiving the response as a stream. final static HeaderValueparsedContentTypeHeader(Headers $self)Get the Content-Typeheader, parsed into a HeaderValue.final static StringgetParam(HeaderValue $self, String name)Get a named parameter value from a header (e.g. final static UnitcopyToPipeline(ByteReadChannel $self, IntCoAcceptor<?> acceptor, Integer bufferSize)Copy data from a ByteReadChannel to an IntCoAcceptor. final static KTypegetParamType(TypeInfo $self, Integer index)Get a selected generic class type parameter from a Ktor TypeInfo. -
-
Method Detail
-
getApplicationJSON
final ContentType getApplicationJSON()
The
application/jsoncontent type
-
getApplicationJSONString
final String getApplicationJSONString()
The
application/jsoncontent type as a string
-
kjson
final static Unit kjson(Configuration $self, ContentType contentType, Function1<JSONConfig, Unit> block)
Register the
kjsoncontent converter, configuring theJSONConfigwith a lambda.
-
kjson
final static Unit kjson(Configuration $self, JSONConfig config, ContentType contentType)
Register the
kjsoncontent converter, supplying aJSONConfig.
-
kjson
final static Unit kjson(ContentNegotiation.Config $self, ContentType contentType, Function1<JSONConfig, Unit> block)
Register the
kjsonclient content converter, configuring theJSONConfigwith a lambda.
-
kjson
final static Unit kjson(ContentNegotiation.Config $self, JSONConfig config, ContentType contentType)
Register the
kjsonclient content converter, supplying aJSONConfig.
-
contentTypeJSON
final static Headers contentTypeJSON()
Get a Headers containing a
Content-Typeofapplication/json.
-
contentTypeJSON
final static Headers contentTypeJSON(Charset charset)
Get a Headers containing a
Content-Typeofapplication/jsonwith the specified Charset.
-
channelOutput
final static KtorByteChannelOutput channelOutput(ByteWriteChannel channel, Charset charset)
Create a KtorByteChannelOutput (convenience function).
-
createStreamedJSONContent
final static OutgoingContent createStreamedJSONContent(Object value, ContentType contentType, Charset charset, JSONConfig config)
Create an OutgoingContent to stream JSON output.
-
respondStream
final static Unit respondStream(ApplicationCall $self, ContentType contentType, HttpStatusCode status, Long contentLength, Charset charset, SuspendFunction1<SuspendFunction1<Character, Unit>, Unit> producer)
Respond to a call using streamed data.
- Parameters:
contentType- the ContentTypestatus- the HttpStatusCode being returnedcontentLength- the content length (if known)charset- the Charsetproducer- the producer function which will write the data to a CoOutput (supplied as receiver)
-
receiveStreamJSON
final static <T extends Any> Unit receiveStreamJSON(HttpClient $self, String urlString, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)
Make a client call, receiving the response as a stream. The response must be in the form of a JSON array, and each array item will be deserialized and passed to the
consumerfunction as it is received.- Parameters:
urlString- the URL as a Stringmethod- the HTTP method (default GET)body- the request body if requiredexpectedStatus- the expected response status (default 200 OK)config- the JSONConfig to use when deserializingconsumer- the consumer function (will be called with each array item)
-
receiveStreamJSON
final static <T extends Any> Unit receiveStreamJSON(HttpClient $self, KType type, String urlString, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)
Make a client call, receiving the response as a stream. The response must be in the form of a JSON array, and each array item will be deserialized and passed to the
consumerfunction as it is received.- Parameters:
type- the type of the array item as a KTypeurlString- the URL as a Stringmethod- the HTTP method (default GET)body- the request body if requiredexpectedStatus- the expected response status (default 200 OK)config- the JSONConfig to use when deserializingconsumer- the consumer function (will be called with each array item)
-
receiveStreamJSON
final static <T extends Any> Unit receiveStreamJSON(HttpClient $self, Url url, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)
Make a client call, receiving the response as a stream. The response must be in the form of a JSON array, and each array item will be deserialized and passed to the
consumerfunction as it is received.- Parameters:
url- the URL as a Urlmethod- the HTTP method (default GET)body- the request body if requiredexpectedStatus- the expected response status (default 200 OK)config- the JSONConfig to use when deserializingconsumer- the consumer function (will be called with each array item)
-
receiveStreamJSON
final static <T extends Any> Unit receiveStreamJSON(HttpClient $self, KType type, Url url, HttpMethod method, Object body, Headers headers, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)
Make a client call, receiving the response as a stream. The response must be in the form of a JSON array, and each array item will be deserialized and passed to the
consumerfunction as it is received.- Parameters:
type- the type of the array item as a KTypeurl- the URL as a Urlmethod- the HTTP method (default GET)body- the request body if requiredexpectedStatus- the expected response status (default 200 OK)config- the JSONConfig to use when deserializingconsumer- the consumer function (will be called with each array item)
-
executeStreamJSON
final static <T extends Any> Unit executeStreamJSON(HttpClient $self, KType type, HttpRequestBuilder requestBuilder, HttpStatusCode expectedStatus, JSONConfig config, SuspendFunction1<T, Unit> consumer)
Make a client call with the parameters supplied in a HttpRequestBuilder, receiving the response as a stream. The response must be in the form of a JSON array, and each array item will be deserialized and passed to the
consumerfunction as it is received.- Parameters:
type- the type of the array item as a KTypeexpectedStatus- the expected response status (default 200 OK)config- the JSONConfig to use when deserializingconsumer- the consumer function (will be called with each array item)
-
parsedContentTypeHeader
final static HeaderValue parsedContentTypeHeader(Headers $self)
Get the
Content-Typeheader, parsed into a HeaderValue.
-
getParam
final static String getParam(HeaderValue $self, String name)
Get a named parameter value from a header (e.g. the
charsetvalue inapplication/json;charset=UTF-8).
-
copyToPipeline
final static Unit copyToPipeline(ByteReadChannel $self, IntCoAcceptor<?> acceptor, Integer bufferSize)
Copy data from a ByteReadChannel to an IntCoAcceptor.
-
getParamType
final static KType getParamType(TypeInfo $self, Integer index)
Get a selected generic class type parameter from a Ktor TypeInfo.
-
-
-
-