{"id":20742435,"url":"https://github.com/luizguilhermesj/generic-rest-api","last_synced_at":"2025-07-10T12:41:53.543Z","repository":{"id":57143850,"uuid":"77870922","full_name":"luizguilhermesj/generic-rest-api","owner":"luizguilhermesj","description":"Node JS generic rest api based on your models","archived":false,"fork":false,"pushed_at":"2023-03-01T16:23:14.000Z","size":219,"stargazers_count":9,"open_issues_count":4,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-26T06:50:10.616Z","etag":null,"topics":["express","express-middleware","expressjs","generator","rest","rest-api","sequelize"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luizguilhermesj.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-03T00:27:26.000Z","updated_at":"2024-04-29T14:36:18.000Z","dependencies_parsed_at":"2025-04-24T05:11:40.292Z","dependency_job_id":"2bf3b3d7-e2b6-47ce-88a7-85fecd12eb38","html_url":"https://github.com/luizguilhermesj/generic-rest-api","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/luizguilhermesj/generic-rest-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizguilhermesj%2Fgeneric-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizguilhermesj%2Fgeneric-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizguilhermesj%2Fgeneric-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizguilhermesj%2Fgeneric-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luizguilhermesj","download_url":"https://codeload.github.com/luizguilhermesj/generic-rest-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizguilhermesj%2Fgeneric-rest-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264579242,"owners_count":23631566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","express-middleware","expressjs","generator","rest","rest-api","sequelize"],"created_at":"2024-11-17T07:05:43.597Z","updated_at":"2025-07-10T12:41:53.493Z","avatar_url":"https://github.com/luizguilhermesj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/luizguilhermesj/generic-rest-api.svg?branch=master)](https://travis-ci.org/luizguilhermesj/generic-rest-api)\n\n# generic-rest-api\nExpress JS generic REST API based on your sequelize models\n\nThe goal is to make something that we can use to build APIs really fast, instead of using a full framework like [sailsjs](http://sailsjs.com/) or [loopback](http://loopback.io/)\n\n\n#### Requirements\n\n* expressjs\n* sequelize\n\n#### Getting Started\n\nFirst you add generic-rest-api to your project:\n\n```shell\nnpm install --save generic-rest-api\n```\n\nThen you add it as a middleware to your express app, informing the path where your sequelize models are:\n\n```javascript\nvar genericRestApi = require('generic-rest-api');\n...\napp.use(genericRestApi(__dirname+'/models'));\n```\n\nLet's assume you have just one model named `user`. The first example will add your application the following routes:\n\nGET /user  \nGET /user/:id  \nGET /user/:id/:relation  \nPOST /user  \nPUT /user/:id  \nDELETE /user/:id  \n\nIf you want to add a prefix to your API you just need to declare it in express use:\n\n```javascript\napp.use('/api/v2', genericRestApi(__dirname+'/models'));\n```\n\nThis way your API will be:\n\nGET /api/v2/user\n[...]\n\nYou can also add some middlewares to all generic rest routes using an options argument:\n\n```javascript\nvar options = {\n    middlewares: [\n        authentication\n    ]\n};\napp.use(genericRestApi(__dirname+'/models', options));\n```\n\n#### Aditional Parameters  \nIn way to perform more specific queries, you can pass some parameters while accessing your API route.\n\n**Filter results by specif value (works as sql 'where [name] = [value]')**  \nall parameters passed as get method will be treated as a 'WHERE' rule\n```\nGET /api/v2/user/?firstName=Luiz\n```\n\n**Show only specific fields**  \nTo return only specif fields, you can pass a parameter called 'fields' separeted by comma.\n```\nGET /api/v2/user/?firstName=Luiz\u0026fields=user_id,age,fullName\n```\n\n**Making field relations**  \nIf a foreign key is set to a field, you can pass with a parameter called 'populate' in order to have it retrieve within your API response. If you have more than one relation, you can pass it also separated by comma\n```\nGET /api/v2/user/?firstName=Luiz\u0026fields=user_id,age,fullName\u0026populate=company,...\n```\n\n***Advanced where queries***  \nIn order to have advanced queries with 'LIKE' on 'WHERE', you can specify an JSON just like sequelize accepts\n```\nGET /api/v1/user/?where={\"name\":{\"$like\":\"%25Luiz%25\"}}\n```\n\nImportant notes:\n* If you pass 'WHERE' parameter, all others other filter rules passed by get method will be overwritten.\n* You need to specify the operator name with a \"$\" as a prefix.\n* You can find a list of all operators accepted on http://docs.sequelizejs.com/manual/tutorial/querying.html#operators\n\n#### Authentication  \n\nThere is no authentication in this module.\nI know I'm forcing your hand here, but you can use a middleware for authentication and hooks on models for authorization.\n\n\n#### Obs  \n\nIf you want to override any method, you just need to add your own custom route BEFORE the middleware.\n\n#### Issues\n\nIf you find any kind of issue, please make this world more beautiful and **report** this [**issue**](https://github.com/luizguilhermesj/generic-rest-api/issues) so I can correct it.\nAnd, of course, if you want you can always make a [**pull request**](https://github.com/luizguilhermesj/generic-rest-api/pulls).\n\n#### Next Steps\n\n* support Restify\n* support other ORMs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizguilhermesj%2Fgeneric-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluizguilhermesj%2Fgeneric-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizguilhermesj%2Fgeneric-rest-api/lists"}