andywer / andywer/ideabox

Frontend ORM for handling REST resources

Open
#2 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

I think it would be very useful to have something like an ORM for the frontend to fetch and manipulate REST resources. Especially if your backend goes an HATEOASish approach, since you want a tight coupling of resource and href (see https://www.npmjs.com/package/hal). There seems to be no suitable solution out there: https://www.google.de/search?q=redux%20hateoas

Idea:

``` js
////////////////
// Basic usage:

const User = createRestResourceType('user')

const user = await User.fetch('/href/to/user')
const users = await User.fetchAll('/href/to/all/users')

let newUser
// create new empty user instance, do not POST to server yet
newUser = User.new(userData)
// create new user instance, provide data, POST immediately
newUser = await User.create('/href/to/POST/to', userData)

user.update(userData)
user.destroy()

// API should be quite similar to existing JS ORMs like mongoose & sequelize
// Enumerating an instance's properties returns exactly the underlying REST object's properties

///////////////////
// Redux bindings:

bindActionCreators(User)
const reducers = reducersFor(User)

///////////////////////////////
// What the bindActionCreators() does:

User.on('fetchSuccess', (href, data) => (
dispatch({
// could use https://www.npmjs.com/package/action-names
type: actionTypesFor(User).fetchSuccess,
payload: { href, data: User.new(data) }
})
))

// ...
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.