-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds 5 shorthand functions for request verbs get, post, put, patch, d…
…estroy (#10) close #9 This PR adds shorthand functions to directly call one specific HTTP request verb. 5 new functions are available : get, post, put, patch, destroy ### Example ```js import {get, post, put, patch, destroy} from '@rails/request.js' async myMethod () { const response = await post('localhost:3000/my_endpoint', { body: { name: 'Request.JS' }})) if (response.ok) { const body = await response.text ... } } ``` ### DELETE -> `destroy` `delete` is a javascript reserved word so for this shorthand function I used `destroy`
- Loading branch information
1 parent
72bb933
commit 0f0dbe4
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { FetchRequest } from './fetch_request' | ||
import { FetchResponse } from './fetch_response' | ||
import { RequestInterceptor } from './request_interceptor' | ||
import { get, post, put, patch, destroy } from './verbs' | ||
|
||
export { FetchRequest, FetchResponse, RequestInterceptor } | ||
export { FetchRequest, FetchResponse, RequestInterceptor, get, post, put, patch, destroy } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FetchRequest } from './fetchRequest' | ||
|
||
async function get (url, options) { | ||
const response = new FetchRequest('get', url, options) | ||
return response.perform() | ||
} | ||
|
||
async function post (url, options) { | ||
const response = new FetchRequest('post', url, options) | ||
return response.perform() | ||
} | ||
|
||
async function put (url, options) { | ||
const response = new FetchRequest('put', url, options) | ||
return response.perform() | ||
} | ||
|
||
async function patch (url, options) { | ||
const response = new FetchRequest('patch', url, options) | ||
return response.perform() | ||
} | ||
|
||
async function destroy (url, options) { | ||
const response = new FetchRequest('delete', url, options) | ||
return response.perform() | ||
} | ||
|
||
export { get, post, put, patch, destroy } |