Skip to content

Commit fe9ac67

Browse files
committed
Document request and response options
1 parent fb4fcb5 commit fe9ac67

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ async myMethod () {
7171
}
7272
```
7373

74+
### responseKind
75+
76+
You can provide this option to specify which kind of response will be accepted. Default is `html`.
77+
78+
Options are `html`, `turbo-stream`, `json`.
79+
80+
### contentType
81+
82+
When provided this value will be sent in the `Content-Type` header. When not provided Request.JS will send nothing when the `body` of the request is `null` or an instance of `FormData`, when the `body` is an instance of a `File` then the type of the file will be sent and `application/json` will be sent if none of the prior conditions matches.
7483

7584
#### Turbo Streams
7685

@@ -81,6 +90,8 @@ import { Turbo } from "@hotwired/turbo-rails"
8190
window.Turbo = Turbo
8291
```
8392

93+
Since [v7.0.0-beta.6](https://github.com/hotwired/turbo/releases/tag/v7.0.0-beta.6) Turbo sets `window.Turbo` automatically.
94+
8495
#### Request Interceptor
8596

8697
To authenticate fetch requests (eg. with Bearer token) you can use request interceptor. It allows pausing request invocation for fetching token and then adding it to headers:
@@ -99,6 +110,40 @@ RequestInterceptor.register(async (request) => {
99110
RequestInterceptor.reset()
100111
```
101112

113+
## Response
114+
115+
### statusCode
116+
117+
Returns the response status.
118+
119+
### ok
120+
121+
Returns true if the response was successful.
122+
123+
### unauthenticated
124+
125+
Returns true if the response has a `401` status code.
126+
127+
### authenticationURL
128+
129+
Returns the value contained in the `WWW-Authenticate` header.
130+
131+
### contentType
132+
133+
Returns the response content-type.
134+
135+
### html
136+
137+
Returns the html body, if the content type of the response isn't `html` then will be returned a rejected promise.
138+
139+
### json
140+
141+
Returns the json body, if the content type of the response isn't `json` then will be returned a rejected promise.
142+
143+
### headers
144+
145+
Returns the response headers.
146+
102147
# Known Issues
103148

104149
`FetchRequest` sets a `"X-Requested-With": "XmlHttpRequest"` header. If you have not upgraded to Turbo and still use `Turbolinks` in your Gemfile, this means

0 commit comments

Comments
 (0)