Backend REST api without the headache
We're building a autogeneated backend api, so you can worry about your customers, and building great applications. This is buildt to simplify everything related to building api's
- What is Saul made of?
- File structure
- Getting Started
- ... More to come
- Mongodb
- Mongoose
- Redis
- Nodejs
- api/ #This is where the magic happens
- helpers/ #Saul needs helpers
- createSchema.js #Used to build the schemas as needed for the api.js
- db.js #Used to initate db connection
- permissions #Functions to verify permissions
- api.js #File where we generate the api based on the api-config.js parsed when running the index.js
- index.js #Project index is where all the modules are ran from
- example/ #Frontend example using the api
- saul-config.js #Config the api using mongoose
- index.js #Example code
- package.json #Modules needed to run the project
- LICENSE #The project license
- npm i -S sauljs
- require Saul
const Saul = require('sauljs')
- Create a saul-config.js
// Declare primary schemas
module.exports = [
{
apiName: 'user', // Define a name for your api this will result in baseUrl + '/user'
fields: {
email: String,
password: String,
birthdate: Number
}, // Here we define the field settings just like in mongoose this is actually forwarded to the mongoose api so the fields work just like mongoose
hiddenFields: ['password'], Here you can define which fields you dont what to return like a password maybe
settings: {
timestamps: true
}, // This settings object is passed on to mongoose as is so you can define all setings in mongoose right here
access: {
getOne: 'std_user',
get: 'moderator',
create: 'moderator',
update: 'moderator',
del: 1000 // Admin
}, // In this section you can define pr method which access level you need to have to do a certain operation, default is that everything is accessable
middleware: {
pre: {
// Modify requests before they hit the database
// All methods is allowed getOne, get, create, update & del
getOne: function(req, res, next) {
next();
}
},
post: {
// Modify requests after they return from the database
// All methods is allowed getOne, get, create, update & del
getOne: function(req, res, next) {
var result = req.apiResult;
res.status(200).json(result);
}
}
}
}
];
- Initiate Saul
let routeConfig = require('./saul-config');
let options = {
baseUrl: '/api',
routeConfig: routeConfig, // Get the routing config you made
cache: true, //Toggle if it should utilize redis caching
allowed_permissions: {
super_admin: 5000,
admin: 1000,
moderator: 750,
std_user: 500
} // Define a permissions array and defining an integer that represent the role in value, the higher the number the higher the permissions
};
let Saul = Saul(options);
app.use('/api', Saul);