Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds 5 shorthand functions for request verbs get, post, put, patch, destroy #10

Merged
merged 7 commits into from
Jun 7, 2021

Conversation

adrienpoly
Copy link
Contributor

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

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

@marcelolx
Copy link
Collaborator

Great @adrienpoly! Could you please add a section on the README about this functionality?

@adrienpoly
Copy link
Contributor Author

@marcelolx I added a small documentation part to the readme

src/verbs.js Outdated Show resolved Hide resolved
@marcelolx marcelolx merged commit 0f0dbe4 into rails:main Jun 7, 2021
@marcelolx
Copy link
Collaborator

Thanks @adrienpoly

@adrienpoly adrienpoly deleted the shorthand-verbs branch June 8, 2021 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shorthand methods : get, post, put, delete
2 participants