restful-proxy
Probably the most elegant RESTful HTTP client.
One second to get started!
// GET /user/profile/avatar
let res = await restful.user.profile.avatar.get();
// POST /user/profile with data
res = await restful.user.profile.post({
body: JSON.stringify({ name: 'mrthanlon' })
});
// DELETE /post/me/lastyear
res = await restful.post.me.lastyear.delete();
By default we use fetch() to send the request, you can also use it with axios if you don't like fetch(), or you can also use your own callback function at:
restful.requestCallback = (input, init) => {
console.log(input, init);
}
You can set baseURL
like this:
restful.options = {
baseURL: 'http://example.com'
};
Installing
Browser
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/restful-proxy/dist/restful.min.js"></script>
Node.js & Webpack & Vite & rollup...
Using npm:
npm install restful-proxy
Notice
In the interactive environment (REPL), since it may run automatically when typing, which may cause URL errors, it is not recommended to use it in an interactive environment.