francescosaveriozuppichini / api-class Goto Github PK
View Code? Open in Web Editor NEWA utility class for calling apis CRUD methods
A utility class for calling apis CRUD methods
Thanks for this amazing utility! I can't seem to make it work though. I followed the instructions. This is my code:
import API from 'api-class';
const myAPI = new API({ url: 'http://baerenmatte.test/api' });
myAPI.createEntity({ name: 'events' });
myAPI.endpoints.events.getAll()
.then(({data}) => console.log(data));
And this is the error I get in the console:
API.js:68 Uncaught TypeError: Cannot read property 'query' of undefined
at Object.endpoints.getAll (API.js:68)
at Module.<anonymous> (app.js:102)
at Module../site/resources/js/app.js (app.js:30155)
at __webpack_require__ (bootstrap:19)
at Object.0 (app.js:31559)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
What am I doing wrong?
Would be nice if this nice little package allowed to use PATCH method on resources. Should be easy to do, I might make a PR later today.
What if the resourceUrl path has a hyphen?
API.createEntity({ name: 'data-systems' });
Current code
Line 41 in 63bef06
endpoints.getAll = ({ query={}}, config={} ) => axios.get(resourceURL, Object.assign({ params: { query }, config }))
here the merge is not happening properly, because of which headers are not sent.
The below code will fix the problem
Object.assign({ params: { query } }, config)
BTW all other methods are working fine
I was thinking that it may be useful to add a local cache in order to store some requests. Maybe having a parameter to specify the cache size.
Please, add headers parameters as an option to authenticate a token.
Actually tried to implement API class in tsx file taken from that medium blog. it is giving type error. can you write the same for tsx. it would be a great help.
actually i edited it to make it compatible with tsx, but at time of running, it says, query is not defined when try to call getAll()
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.