Skip to content

Commit ca99f1d

Browse files
authored
update docs, increment version (#60)
Updated docs for recent changes. Incremented patch version for tagging.
1 parent 0053243 commit ca99f1d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
44
license = "MIT"
55
desc = "OpenAPI server and client helper for Julia"
66
authors = ["JuliaHub Inc."]
7-
version = "0.1.16"
7+
version = "0.1.17"
88

99
[deps]
1010
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

docs/src/userguide.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Client(root::String;
124124
timeout::Int=DEFAULT_TIMEOUT_SECS,
125125
long_polling_timeout::Int=DEFAULT_LONGPOLL_TIMEOUT_SECS,
126126
pre_request_hook::Function,
127+
escape_path_params::Union{Nothing,Bool}=nothing,
128+
chunk_reader_type::Union{Nothing,Type{<:AbstractChunkReader}}=nothing,
127129
verbose::Union{Bool,Function}=false,
128130
)
129131
```
@@ -136,12 +138,16 @@ Where:
136138
- `timeout`: optional timeout to apply for server methods (default `OpenAPI.Clients.DEFAULT_TIMEOUT_SECS`)
137139
- `long_polling_timeout`: optional timeout to apply for long polling methods (default `OpenAPI.Clients.DEFAULT_LONGPOLL_TIMEOUT_SECS`)
138140
- `pre_request_hook`: user provided hook to modify the request before it is sent
141+
- `escape_path_params`: Whether the path parameters should be escaped before being used in the URL (true by default). This is useful if the path parameters contain characters that are not allowed in URLs or contain path separators themselves.
142+
- `chunk_reader_type`: The type of chunk reader to be used for streaming responses.
139143
- `verbose`: whether to enable verbose logging
140144

141145
The `pre_request_hook` must provide the following two implementations:
142146
- `pre_request_hook(ctx::OpenAPI.Clients.Ctx) -> ctx`
143147
- `pre_request_hook(resource_path::AbstractString, body::Any, headers::Dict{String,String}) -> (resource_path, body, headers)`
144148

149+
The `chunk_reader_type` can be one of `LineChunkReader`, `JSONChunkReader` or `RFC7464ChunkReader`. If not specified, then the type is automatically determined based on the return type of the API call. Refer to the [Streaming Responses](#Streaming-Responses) section for more details.
150+
145151
The `verbose` option can be one of:
146152
- `false`: the default, no verbose logging
147153
- `true`: enables curl verbose logging to stderr
@@ -191,3 +197,20 @@ Optional middlewares can be one or more of:
191197

192198
The order in which middlewares are invoked is:
193199
`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke`
200+
201+
## Streaming Responses
202+
203+
Some OpenAPI implementations implement streaming of responses by sending more than one items in the response, each of which is of the type declared as the return type in the specification. E.g. the [Twitter OpenAPI specification](https://api.twitter.com/2/openapi.json) that keeps sending tweets in JSON like this forever:
204+
205+
```json
206+
{"data":{"id":"1800000000000000000","text":"mmm i like a sandwich"},"matching_rules":[{"id":1800000000000000000,"tag":"\"sandwich\""}]}
207+
{"data":{"id":"1800000000000000001","text":"lets have a sandwich"},"matching_rules":[{"id":1800000000000000001,"tag":"\"sandwich\""}]}
208+
```
209+
210+
OpenAPI.jl handles such responses through "chunk readers" which are engaged only with the streaming API endpoints. There can be multiple implementations of chunk readers, each of which must be of type `AbstractChunkReader`. The following are the chunk readers provided, each with a different chunk detection strategy. They are selected based on some heuristics based on the response data type.
211+
212+
- `LineChunkReader`: Chunks delimited by newline. This is the default when the response type is detected to be not of `OpenAPI.APIModel` type.
213+
- `JSONChunkReader`: Each chunk is a JSON. Whitespaces between JSONs are ignored. This is the default when the response type is detected to be a `OpenAPI.APIModel`.
214+
- `RFC7464ChunkReader`: A reader based on [RFC 7464](https://www.rfc-editor.org/rfc/rfc7464.html). Available for use by overriding through `Client` or `Ctx`.
215+
216+
The `OpenAPI.Clients.Client` and `OpenAPI.Clients.Ctx` constructors take an additional `chunk_reader_type` keyword parameter. This can be one of `OpenAPI.Clients.LineChunkReader`, `OpenAPI.Clients.JSONChunkReader` or `OpenAPI.Clients.RFC7464ChunkReader`. If not specified, then the type is automatically determined as described above.

src/client.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ end
107107
timeout::Int=DEFAULT_TIMEOUT_SECS,
108108
pre_request_hook::Function=noop_pre_request_hook,
109109
escape_path_params::Union{Nothing,Bool}=nothing,
110+
chunk_reader_type::Union{Nothing,Type{<:AbstractChunkReader}}=nothing,
110111
verbose::Union{Bool,Function}=false,
111112
)
112113

0 commit comments

Comments
 (0)