Skip to content

Instantly share code, notes, and snippets.

@gwenaelp
Created August 3, 2018 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwenaelp/c37c1d711dac4b7299e87e59239aab1e to your computer and use it in GitHub Desktop.
Save gwenaelp/c37c1d711dac4b7299e87e59239aab1e to your computer and use it in GitHub Desktop.
const express = require('express');
const schemas = [{
name: 'user',
apiType: 'CRUD',
apiEndPoint: 'user',
apiGetKey: 'name',
fields: [/* ... */],
}];
const app = express();
for (let i = 0; i < schemas.length; i++) {
const currentSchema = schemas[i];
if(currentSchema.apiType === 'CRUD') {
app.get(`/${currentSchema.apiEndPoint}`, (req, res) => {});
app.delete(`/${currentSchema.apiEndPoint}/:${currentSchema.apiGetKey}`, (req, res) => {
/* ... */
});
app.post(`/${currentSchema.apiEndPoint}/:${currentSchema.apiGetKey}`, (req, res) => {
/* ... */
});
app.put(`/${currentSchema.apiEndPoint}/:${currentSchema.apiGetKey}`, (req, res) => {
/* ... */
});
}
}
app.listen('9000', () => console.log(`Server listening on port 9000!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment