Skip to content

Commit 6a69ac2

Browse files
committed
Add prefix Fetch to Request and Response classes
As pointed in #3 the actual Request/Response classes clashes with the built-in classes from JS
1 parent c8d7881 commit 6a69ac2

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Request } from './request'
2-
import { Response } from './response'
1+
import { FetchRequest } from './fetch_request'
2+
import { FetchResponse } from './fetch_response'
33

4-
export { Request, Response }
4+
export { FetchRequest, FetchResponse }

0 commit comments

Comments
 (0)