![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@guillaumejasmin/axios-rest
Advanced tools
Axios Rest - Tool for build REST resources with axios
Build resources and actions for axios
npm install axios-rest --save
A resource is a REST endpoint, with a list of actions.
Globals resource actions are actions available for all resources.
The most common resource actions are CRUD methods: fetch
, create
, update
and delete
.
Example of posts
resource:
method | URL | description | Axios Rest |
---|---|---|---|
GET | /posts | fetch all post | api.posts().fetch() |
GET | /posts/1 | fetch one post | api.posts(1).fetch() |
POST | /posts | create post | api.posts().create({ data: { title: 'foo' } }) |
PATCH / PUT | /posts/1 | update post | api.posts().update({ { data: id: 1, title: 'bar' } }) |
DELETE | /posts/1 | delete post | api.posts(1).delete() |
A resource can also have custom actions only available for this resource:
method | URL | description | |
---|---|---|---|
POST | /comments/1/like | add a like to the comment 1 | api.comments(1).like() |
POST | /comments/1/unlike | remove a like to the comment 1 | api.comments(1).unlike() |
A resource can have sub resources
method | URL | description | Axios Rest |
---|---|---|---|
GET | /posts/1/comments | fetch all comment of post 1 | api.posts(1).comments().fetch() |
POST | /posts/1/comments | create a comment of post 1 | api.posts(1).comments().create({ data: { text: '...' } }) |
An action is a single endpoint. The most common action is login
method | URL | description | Axios Rest |
---|---|---|---|
POST | /login | login to admin panel | api.login({ data: { username: '...', password: '...' } }) |
POST | /logout | logout from admin panel | api.logout() |
createAxiosRest(axiosInst, config)
axiosInst
- Axios Instance - required - create with axios.create()
. See Axios documentation
config
- object - required
{
idKey: 'id',
resources: undefined,
actions: undefined,
globalResourceActions: undefined // Actions available for all resources
}
{
[resourceName]: {
url: '',
resources: undefined // sub resources
actions: undefined
}
}
{
[actionName]: {
// axios request config
}
}
// or if you need to get resource id
{
[actionName]: (id, data) => ({
// axios request config
})
}
import axios from 'axios'
import { createAxiosRest, CRUDActions } from 'axios-rest'
const axiosInst = axios.create({
baseURL: 'http://api.website.com',
})
const config = {
globalResourceActions: CRUDActions, // use can use predefined CRUD action or build yours
resources: {
posts: {
url: '/posts',
resources: {
comments: {
url: '/comments',
},
},
},
comments: {
url: '/comments',
actions: {
like: id => ({
url: `/${id}/like`,
method: 'POST',
}),
unlike: id => ({
url: `/${id}/unlike`,
method: 'POST',
}),
},
},
},
actions: {
login: {
url: '/login',
method: 'POST',
},
logout: {
url: '/logout',
method: 'POST',
},
},
}
const api = createAxiosRest(axiosInst, config)
// GET /posts
api
.posts()
.fetch()
.then(res => console.log(res.data))
// GET /posts/1
api.posts(1).fetch()
// POST /posts
api.posts().create({ data: { title: '...' } })
// PATCH /posts/1
api.posts().update({ data: { id: 1, title: '...' } })
// or
api.posts(1).update({ data: { title: '...' } })
// PUT /posts/1
api.posts().update({ data: { id: 1, title: '...' }, method: 'put' })
// DELETE /posts/1
api.posts(1).delete()
api.login({ data: { email: '...', password: '...' } }).then(res => {
// success login
})
// GET /posts/1/comments
api
.posts(1)
.comments()
.fetch()
// POST /posts/1/comments
api
.posts(1)
.comments()
.create({ data: { author: '...', text: 'Amazing article !' } })
// POST /comments/1/like
api.comments(1).like()
const config = {
actions: {
myAction: (id, data) => ({
url: `custom-action/${data.postId}/${data.commentId}`,
}),
},
}
// ...
api.myAction({ data: { postId: '', commentId: '' } })
id
is unused here, because it's an action. Id can only be used with resource: api.posts(id).anotherAction()
You have 2 ways to set axios config for an action:
const config = {
actions: {
myAction: {
url: 'custom-action',
method: 'GET',
headers: {
X_CUSTOM_HEADER: 'foo',
},
params: {
page: 1,
},
},
},
}
// ...
// GET /custom-action&page=1
// with header X_CUSTOM_HEADER
api.myAction()
// GET /custom-action&page=2&lang=en
// with header X_CUSTOM_HEADER
api.myAction({ params: { page: 2, lang: 'en' } })
FAQs
Axios Rest - Tool for build REST resources with axios
The npm package @guillaumejasmin/axios-rest receives a total of 3 weekly downloads. As such, @guillaumejasmin/axios-rest popularity was classified as not popular.
We found that @guillaumejasmin/axios-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.