rails / request.js

MIT License
390 stars 28 forks source link

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

Closed adrienpoly closed 3 years ago

adrienpoly commented 3 years ago

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 commented 3 years ago

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

adrienpoly commented 3 years ago

@marcelolx I added a small documentation part to the readme

marcelolx commented 3 years ago

Thanks @adrienpoly