Skip to content

Commit c7a6374

Browse files
authored
Merge branch 'main' into shorthand-verbs
2 parents 6b92888 + a4ba4ac commit c7a6374

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ yarn add @rails/request.js
1515

1616
# How to use
1717

18-
Just import the `Request` class from the package and instantiate it passing the request `method`, `url`, `options`, then call `await request.perform()` and do what do you need with the response.
18+
Just import the `FetchRequest` class from the package and instantiate it passing the request `method`, `url`, `options`, then call `await request.perform()` and do what do you need with the response.
1919

2020
Example:
2121

@@ -25,7 +25,7 @@ import { Request } from '@rails/request.js'
2525
....
2626

2727
async myMethod () {
28-
const request = new Request('post', 'localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})
28+
const request = new FetchRequest('post', 'localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})
2929
const response = await request.perform()
3030
if (response.ok) {
3131
const body = await response.text

src/request.js renamed to src/fetch_request.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Response } from './response'
1+
import { FetchResponse } from './fetch_response'
22
import { getCookie } from './lib/cookie'
33

4-
export class Request {
4+
export class FetchRequest {
55
constructor (method, url, options = {}) {
66
this.method = method
77
this.url = url
88
this.options = options
99
}
1010

1111
async perform () {
12-
const response = new Response(await window.fetch(this.url, this.fetchOptions))
12+
const response = new FetchResponse(await window.fetch(this.url, this.fetchOptions))
1313
if (response.unauthenticated && response.authenticationURL) {
1414
return Promise.reject(window.location.href = response.authenticationURL)
1515
} else {

src/response.js renamed to src/fetch_response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export class Response {
1+
export class FetchResponse {
22
constructor (response) {
33
this.response = response
44
}

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Request } from './request'
2-
import { Response } from './response'
3-
import {get, post, put, patch, destroy} from './verbs'
1+
import { FetchRequest } from './fetch_request'
2+
import { FetchResponse } from './fetch_response'
3+
import { get, post, put, patch, destroy } from './verbs'
44

5-
export { Request, Response, get, post, put, patch, destroy}
5+
export { FetchRequest, FetchResponse, get, post, put, patch, destroy }

0 commit comments

Comments
 (0)