Overview
@uteamjs/node is a backend RESTful API framework built on top of the Node.js and Express.js ecosystem. It can be deployed alone or together with frontend @uteamjs/react framework. It is not required to set up any API endpoint in Express.js. You simply put the backend functions in standard node_modules component structure. This helps to simplify the deployment and management of complex enterprise applications.
Integrate with @uteamjs/react
#
In this following example, the name of the reducer ‘crud-api/contact’ defines the <package>/<component> destination.
const reducer = utReducer('crud-api/contact', {
actions: {
...
load: (_, payload) => _.rows = payload.rows
}
})
class layout extends utform {
constructor(props) {
...
props.api('load', {})
}
...
}
actions: {
...
load: (_, payload) => _.rows = payload.rows
}
})
class layout extends utform {
constructor(props) {
...
props.api('load', {})
}
...
}
In the server you need to create a contact.js file under the following folder structure:
//your-application/ ... packages/ crud-api/ contact.js ...
Under the contact.js file, add the load function:
const { sqlseries, capitalize } = require('@uteamjs/node')
exports.load = sqlseries((db, payload) => [
db.query('select * from contact', rows => {
rows.forEach(t => t.gender = capitalize(t.gender))
payload.rows = rows
})
])
exports.load = sqlseries((db, payload) => [
db.query('select * from contact', rows => {
rows.forEach(t => t.gender = capitalize(t.gender))
payload.rows = rows
})
])
Corresponding frontend layout:
class layout extends _layout {
constructor(props) {
super(props)
props.api('load', {})
}
render = () => this.Content()
}
constructor(props) {
super(props)
props.api('load', {})
}
render = () => this.Content()
}
Please refer to the Crud Api tutorial for more details.