{"id":16060542,"url":"https://github.com/robinfr/morest","last_synced_at":"2025-03-18T05:30:26.785Z","repository":{"id":31737748,"uuid":"35303753","full_name":"Robinfr/morest","owner":"Robinfr","description":"Allows developers to quickly create RESTful APIs using MongoDB and Express.","archived":false,"fork":false,"pushed_at":"2017-09-25T07:37:41.000Z","size":17,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T17:11:50.308Z","etag":null,"topics":["express-router","mongodb","mongoose","nodejs","router"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Robinfr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-08T21:59:49.000Z","updated_at":"2017-09-25T07:37:07.000Z","dependencies_parsed_at":"2022-07-20T06:32:17.364Z","dependency_job_id":null,"html_url":"https://github.com/Robinfr/morest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robinfr%2Fmorest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robinfr%2Fmorest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robinfr%2Fmorest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robinfr%2Fmorest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Robinfr","download_url":"https://codeload.github.com/Robinfr/morest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244164469,"owners_count":20408940,"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-router","mongodb","mongoose","nodejs","router"],"created_at":"2024-10-09T04:05:18.348Z","updated_at":"2025-03-18T05:30:26.246Z","avatar_url":"https://github.com/Robinfr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Morest #\n\nAllows developers to quickly create RESTful APIs using a mix of MongoDB, Express and NodeJS.\n\n### Using Morest ###\n\n#### Morest generator ####\nThe quickest way to get started with Morest is by using the [Morest generator](https://github.com/Robinfr/generator-morest).\n\n#### Manually ####\n\nInstall using npm: `npm install morest --save`\n\nThe basic idea behind Morest is to write as little boilerplate code as possible. To get started all you have to do is\ndefine the MongoDB schema using Mongoose and add the routes to an Express Router.\n \n**app/controllers/bear.js:**\n\n```javascript\nvar mongoose = require('mongoose'), \n    Schema = mongoose.Schema,\n    morest = require('morest'),\n    Controller = morest.Controller;\n\nvar BearSchema = new Schema({\n    name: {type: String, required: true},\n    type: String\n});\n\nmongoose.model('Bear', BearSchema);\n\nvar BearController = new Controller({\n    model: 'Bear',\n    availableOperations: [\n        'GET_ALL',\n        'GET'\n    ]\n});\n\nmodule.exports = BearController;\n```\n\nThen set up a server to use the controller.\n\n**server.js:**\n\n```javascript\nvar express = require('express'),\n    app = express(),\n    router = express.Router(),\n    mongoose = require('mongoose'),\n    bodyParser = require('body-parser'),\n    morest = require('morest').Morest;\n\nmongoose.connect('mongodb://127.0.0.1:27017/bears');\n\nvar BearController = require('./app/controllers/bear');\n\napp.use(bodyParser.urlencoded({extended: true}));\napp.use(bodyParser.json());\n\nvar port = 8000;\n\napp.use('/api', morest(router, mongoose, {controllers: [BearController]}));\napp.listen(port);\n```\n\n### Defining a controller ###\nMorest comes with its own controllers that allow Morest to easily generate routes. \n\nBefore defining a controller, a Mongoose schema is required.\n\nThe following options can be passed into the controller:\n\n`model`: the name of the Mongoose model\n\n`availableOperations`: array of operations that can be performed with this controller, e.g.: `GET_ALL`, `GET`, \n`POST`, `UPDATE`, `DELETE`. By default, all operations are enabled.\n\n### Generating the routes ###\nGenerating CRUD routes is simple. \n\nFirst create an Express router by doing: `var router = express.Router()`.\n\nThen generate the routes by adding them to your app: `app.use('/api', morest(router, mongoose, {controllers: \n[ControllerObject1, ControllerObject2]}))`.\n\nThe routes are generated based on the Mongoose collection names, e.g. bear is turned into `/bears`, and cave is turned \ninto `/caves`.\n\n### Filtering routes ###\nThere is a basic implementation of filtering available by default in each collection. This allows someone to filter \nitems based on the URL. \n\nFor example, searching for just grizzly bears could be done by navigating to the endpoint `/bears/?type=grizzly bear`.\n\nYou can also limit results by using `?limit=10` or skip results by using `?skip=10`.\n\nIf you want to perform more advanced filtering you can also use Javascript filtering by using `$where` in the URL, \ne.g.: `/bears/?$where=this.type.indexOf(\"Grizzly\")\u003e-1`.\n\n### Customizing controllers ###\nThe base controller has one function for each operation. In case more advanced features are required for a certain \ncontroller they can easily be overwritten. \n\nFor example:\n\n```javascript\nvar BearController = new Controller({\n    model: 'Bear'\n});\n\nBearController.GET = function(req, res){\n    res.send('We dont have any bears yet!');\n};\n```\n\n# Contribute #\nIf you are willing to contribute, feel free to open an issue or create a pull request.\n\n\n## Running tests ##\nThe tests can be run with ``npm test``. This will start the mocha tests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinfr%2Fmorest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinfr%2Fmorest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinfr%2Fmorest/lists"}