Skip to content

Commit e27352b

Browse files
docs: add raw response readme documentation (#268)
1 parent d1c8a94 commit e27352b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ val currentTime: CurrentTimeRetrieveResponse = client.currentTime().retrieve()
146146

147147
The asynchronous client supports the same options as the synchronous one, except most methods are [suspending](https://kotlinlang.org/docs/coroutines-guide.html).
148148

149+
## Raw responses
150+
151+
The SDK defines methods that deserialize responses into instances of Kotlin classes. However, these methods don't provide access to the response headers, status code, or the raw response body.
152+
153+
To access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:
154+
155+
```kotlin
156+
import org.onebusaway.core.http.Headers
157+
import org.onebusaway.core.http.HttpResponseFor
158+
import org.onebusaway.models.CurrentTimeRetrieveParams
159+
import org.onebusaway.models.CurrentTimeRetrieveResponse
160+
161+
val currentTime: HttpResponseFor<CurrentTimeRetrieveResponse> = client.currentTime().withRawResponse().retrieve()
162+
163+
val statusCode: Int = currentTime.statusCode()
164+
val headers: Headers = currentTime.headers()
165+
```
166+
167+
You can still deserialize the response into an instance of a Kotlin class if needed:
168+
169+
```kotlin
170+
import org.onebusaway.models.CurrentTimeRetrieveResponse
171+
172+
val parsedCurrentTime: CurrentTimeRetrieveResponse = currentTime.parse()
173+
```
174+
149175
## Error handling
150176

151177
The SDK throws custom unchecked exception types:

0 commit comments

Comments
 (0)