This package looks promising as a replacement for the good old Rails.ajax
I would suggest to provide, in addition to the Class base request constructor some shorthand version for the 4 main verbs
so that we could write the example like that
import { post } 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
// Do whatever do you want with the response body
// You also are able to call `response.html` or `response.json`, be aware that if you call `response.json` and the response contentType isn't `application/json` there will be raised an error.
}
}
For me, this would feel more idiomatic
implementation could be something like
async post = (url, options) {
const request = new Request('post', url, options)
return request.perform()
}
This package looks promising as a replacement for the good old Rails.ajax
I would suggest to provide, in addition to the Class base request constructor some shorthand version for the 4 main verbs
so that we could write the example like that
For me, this would feel more idiomatic
implementation could be something like
I can submit a PR if this is of interest