victor-am / rails-ranger Goto Github PK
View Code? Open in Web Editor NEWπ€ An opinionated AJAX client for Ruby on Rails APIs
Home Page: https://victor-am.github.io/rails-ranger/
License: MIT License
π€ An opinionated AJAX client for Ruby on Rails APIs
Home Page: https://victor-am.github.io/rails-ranger/
License: MIT License
When running yarn install, I see the following warning
warning rails-ranger > [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see axios/axios#3410
Currently the RailsRanger#index
method is not showing up in the docs and the RailsRanger#list
method is showing up as global.
I am trying to copy the example in the readme, with the following code, but I get the error: this.client is undefined. If I change this.client
to client
it works fine.
import RailsRanger from 'rails-ranger';
const client = new RailsRanger;
export default {
client,
orders: {
update(params) {
return this.client.update('orders', params) // <-- error on this line
.then(response => response.data)
}
}
};
Given the following controller:
class ThingController < ApplicationController
def index
@things = Things.all
respond_to do |format|
format.html
format.json { render json: @things }
end
end
and the following JavaScript:
api.list('things').then((response) => {
console.log(response.data)
})
then response.data
contains the HTML of /things
rather JSON. If I visit /things.json
in the browser I get the expected JSON.
I can't see how to configure rails-ranger or axios to append .json
to the URL. Is this possible? Sadly, calling api.list('things.json')
produces a request to things_json
, which doesn't help much.
(I realise that rails-ranger's really intended for use with API-only Rails backends, but it would be extremely useful to be able to have it work for this case, even if that's not the default behaviour, as we don't always have control over the other endβ¦)
Thanks!
Currently we don't support singular resources through the api.action('resource')
API, but it's a desirable feature.
I've played around with some APIs for this but I didn't feel comfortable with any of them.
Suggestions are welcome π
I have the route current_sbm_employees_path | GET | /merchandising/sbm_employees/current(.:format)
I tried to access it with api.resource('sbm_employees').get('current')
but that gives me /merchandising/current
It works correctly if I use api.resource('sbm_employees').list('current')
Based on the documentation it appears that accessing the url with the get method should work too.
Documentation of the transformData
parameter
Let's face it, transformData
might just be the worst name possible since transform
is a very vague verb and data
is almost everything in software.
I'm considering convertKeys
but suggestions are welcome π
Of course the old transformData
should be kept working (with a warning) until the next major version release.
After this code
list(context, { filters }) {
return api.list('characters', { filters }).then((response) => {
context.commit('setItems', response.data)
})
}
Rails received
<ActionController::Parameters {"filters"=>"[object Object]", (...)}>
At the time of writing the build size is 90kb (minified), which is too big for such a simple library (even when accounting for Axios that weights 12.4kb minified).
If we get to around 45kb (minified but without gzip) we can consider closing this issue.
Is request cancellation supported like it is in Axios?
https://github.com/axios/axios#cancellation
The idea is to make Rails Ranger also a solution to handle authenticated requests on the front-end. The idea is very rough so I'm not sure how much Rails Ranger and still keeping consistency to what it is.
I'm keeping this issue as a reminder of a possible evolution path for the library.
Allow things like api.show('user', { id: 1 })
instead of api.show('users', { id: 1 })
through Rails-like inflections.
What is the recommended way to send a file using rails-ranger. I tried copying the form-data example from the axios repo, but it doesn't seem to work. The form has one file in it, but Chrome just shows it sending an empty json object to the server.
For better development experience (so the developer can understand with a glance when a given error is or isn't related to rails ranger).
I'm having trouble getting the parameter substitution to work with more than one parameter:
api.get('/first/:a/second/:b/third/:c', { a: 'A', b: 'B', c: 'C', d: 'D' }).then((r) => {
console.log(r)
}).catch((e) => {
console.log(e)
})
should perform a GET to /first/A/second/B/third/C?d=D
, but instead tries to GET /first/:a/second/:b/third/C?d=D
I've managed to work around this by using api.get(
`first/${a}/second/${b}/third/:c
`)
for now, but it doesn't look very clean (just like attempting to put backticks in a code block in GitHub π )
I can't see anything in _paramsToPath
that could be causing this βΒ do you know what could be going wrong here?
(I did try replicating this with the RouteBuilder, but the import in the README seems to be wrong:
import { RouteBuilder } from RailsRanger
const routes = new RouteBuilder
produces Uncaught Error: Module build failed: SyntaxError: Unexpected token
. Replacing the import with
import { RouteBuilder } from 'rails-ranger'
produces TypeError: __WEBPACK_IMPORTED_MODULE_3_rails_ranger__.RouteBuilder is not a constructor
. What is the correct way to import the RouteBuilder?)
I didn't had the time to investigate deeper, but the following is happening:
π Works fine
api.update('characters', { id: 1 })
β Doesn't work
api.update('characters', { id: 1, character: { firstName: 'John' } })
The second scenario tries tries to request the /characters/:id
URL (seems like it didn't replace the :id
with the given id).
Allow a set of official adapters (like ActiveModelSerializer's JSON API, Attributes, etc) and the possibility of passing a custom adapter to the Rails Ranger client.
I thought something like that:
import RailsRanger from 'rails-ranger'
//
// Official adapter
//
const api = new RailsRanger({
adapter: 'officialAdapterName'
})
//
// Custom adapter
//
const myAdapter = {
// Some object describing the adapter
}
const api = new RailsRanger({
adapter: myAdapter
})
But as always I'm open to suggestions π
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.