Skip to content

Commit 6b0be45

Browse files
committed
Fix docs examples
As pointed out on #23 fetch requires to stringify the body of the request when the Content-Type is application/json, but actualy we don't do this automaticly and in the docs we were suggesting that we doo which is confusing.
1 parent 0eda429 commit 6b0be45

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { FetchRequest } from '@rails/request.js'
2525
....
2626

2727
async myMethod () {
28-
const request = new FetchRequest('post', 'localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})
28+
const request = new FetchRequest('post', 'localhost:3000/my_endpoint', { body: JSON.stringify({ name: 'Request.JS' }) })
2929
const response = await request.perform()
3030
if (response.ok) {
3131
const body = await response.text
@@ -47,7 +47,7 @@ import { get, post, put, patch, destroy } from '@rails/request.js'
4747
...
4848

4949
async myMethod () {
50-
const response = await post('localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})
50+
const response = await post('localhost:3000/my_endpoint', { body: JSON.stringify({ name: 'Request.JS' }) })
5151
if (response.ok) {
5252
...
5353
}
@@ -88,7 +88,7 @@ RequestInterceptor.reset()
8888
you will not be able to check if the request was redirected.
8989

9090
```js
91-
const request = new FetchRequest('post', 'localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})
91+
const request = new FetchRequest('post', 'localhost:3000/my_endpoint', { body: JSON.stringify({ name: 'Request.JS' }) })
9292
const response = await request.perform()
9393
response.redirected // => will always be false.
9494
```

0 commit comments

Comments
 (0)