{"id":21298624,"url":"https://github.com/passabilities/backrest","last_synced_at":"2025-04-14T17:10:42.384Z","repository":{"id":21365045,"uuid":"89648260","full_name":"passabilities/backrest","owner":"passabilities","description":"Rails like Node framework to create simple, pure backend APIs.","archived":false,"fork":false,"pushed_at":"2022-12-09T04:54:36.000Z","size":526,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T05:51:00.820Z","etag":null,"topics":["backend","backend-apis","framework","nodejs","restful-api"],"latest_commit_sha":null,"homepage":"","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/passabilities.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":"2017-04-27T23:20:39.000Z","updated_at":"2024-09-03T05:02:04.000Z","dependencies_parsed_at":"2023-01-12T03:45:31.741Z","dependency_job_id":null,"html_url":"https://github.com/passabilities/backrest","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passabilities%2Fbackrest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passabilities%2Fbackrest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passabilities%2Fbackrest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passabilities%2Fbackrest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/passabilities","download_url":"https://codeload.github.com/passabilities/backrest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923764,"owners_count":21183954,"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":["backend","backend-apis","framework","nodejs","restful-api"],"created_at":"2024-11-21T14:56:13.072Z","updated_at":"2025-04-14T17:10:42.354Z","avatar_url":"https://github.com/passabilities.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backrest [![npm](https://img.shields.io/npm/v/backrest.svg)](https://www.npmjs.com/package/backrest)\n\nRails like Node framework to create simple, pure backend APIs.\n\n## CLI\n\n### Install\n\n`npm i backrest -g`\n\n### Usage\n\n```\n ❯ backrest help\n\n  Usage: backrest [options] [command]\n\n\n  Commands:\n\n    init|i \u003cname\u003e  create blank Backrest template\n    start|s        start the server\n    stop           stop the server\n    help [cmd]     display help for [cmd]\n\n  Options:\n\n    -h, --help  output usage information\n```\n\n### Development\n\nStart the project and watch for file changes.\n\n`backrest s -w`\n\n### Production\n\nStart the project in a background process.\n\n`NODE_ENV=production backrest s -d`\n\nTo stop:\n\n`backrest stop`\n\n## Package Module\n\nThis project uses [ExpressJS](http://expressjs.com/) behind the scenes. Please visit their website to have a better understanding of how routing and requests work.\n\n### Routing\n\nCreating routes are meant to be easy with a very simple structure.\nThey are defined using an array format to allow defining route precedence.\nFormer routes will take precedence over latter ones if they both match the requested URL.\n\nLocation: `config/routes.js`\n\nEach route will need a couple things:\n\n* An action verb\n* URL end point\n* Controller name\n* Action name\n\nThe layout of each route will be in the following format:\n\n```\n['{verb} {url}', '({controller}#){action}' || [{subroutes}]]\n```\n\n* **verb**\n  * `get`, `post`, `patch`, `put`, or `delete`\n* **url**\n  * URL end point that begins at root (leading `/` is optional)\n  * URLs are allowed to have parameters defined denoted using a colon (`:`)\n    * Example: `users/:id`\n* **controller** (optional)\n  * The controller name is the prefix of the file it is defined in. e.g. `users` for `app/controllers/users_controller.js`\n  * May be omitted to set the controller name to the first part of the route **url**. e.g. `users` for `['get users/all', 'getAll']`\n* **action**\n  * This is the name of the method to call defined in the controller.\n* **subroutes**\n  * Subroutes may be defined instead of a controller and action.\n\nThere are a couple ways to define how routes work:\n\n1. Inline:\n\n  ```javascript\n    module.exports = [\n      ['get users/all', 'users#getAll']\n    ]\n  ```\n\n1. With subroutes:\n\n  ```javascript\n    module.exports = [\n      ['users', [\n        ['get all', 'users#getAll']\n      ]]\n    ]\n  ```\n\n1. Exclude controller name:\n\n  If the root of the URL is the same as the controller name, you may exclude it in the route definition. Both of the following point to the `users` controller:\n  ```javascript\n    module.exports = [\n      ['get users/all', 'getAll'],\n      ['users', [\n        ['get all', 'getAll']\n      ]]\n    ]\n  ```\n\n1. [With `resources` verb](#resources):\n\n  ```javascript\n    module.exports = [\n      ['resources users']\n    ]\n  ```\n\n#### Resources\n\nAuto generate resource routes with the `['resources {name}']` route format.\n\nThe **name** of the resource must be a single word.\n\nThe following routes will be generated:\n\n```javascript\n  [{name}, [\n    [`get /`,       'fetchAll'],\n    [`get /:id`,    'fetch'],\n    [`post /`,      'create'],\n    [`patch /:id`,  'update'],\n    [`put /:id`,    'replace'],\n    [`delete /:id`, 'destroy']\n  ]]\n```\n\n### Controllers\n\nControllers are used to define the actions to take place on each request.\n\nThey should be saved to the `app/controllers/` directory with the suffix `_controller.js` attached. For example `app/controllers/users_controller.js`\n\n#### Actions\n\nEach action function will have 2 arguments. `req` and `res` standing for `request` and `response` respectfully.\n\n```javascript\n  getAll(req, res) {\n\n  }\n```\n\n#### Before Filters\n\nEach before filter function will have 3 arguments: `req`, `res`, and `next`\n\nBefore filters can do perform the following tasks:\n  * Execute any code.\n  * Make changes to the request and the response objects.\n  * End the request-response cycle.\n  * Call the next before filter or action function for the request.\n\n##### Definition\n\nBefore filters are set in the controller by calling `this.beforeFilter[s]` with object[s] from within the controller `constructor`.\nEach object should contain at least 1 property called `action` which is the reference to or string value of the function to be called.\nOther properties to be used are `only` OR `except` which tell the router which actions to call the before filters for.\n`only` and `except` can be either a string or array of strings denoting the name of the actions.\n\nFilters can also be skipped by calling `this.skipBeforeFilter[s]` with the same rules defined above\n\nFilters are executed in the same order they are defined.\n\nExamples:\n\n```javascript\n  constructor() {\n    super()\n\n    this.beforeFilters([\n      { action: '_checkAdmin', except: ['getPublic'] },\n      { action: this._sayHello }\n    ])\n    this.skipBeforeFilter(\n      { action: this._checkAdmin, only: ['getPublic'] }\n    )\n  }\n\n  _checkAdmin(req, res, next) {\n    let user = getUserById(req.params.id)\n    if(user.isAdmin)\n      next() // Continues to the next filter in the chain.\n    else\n      res // Otherwise, respond to request with error.\n        .status(401)\n        .send('User is not admin. Action is prohibited.')\n  }\n\n  _sayHello(req, res, next) {\n    console.log('Hello!')\n    next()\n  }\n```\n\n### Initializers\n\nInitializers are used to run scripts before the server is started. To create an initializer script, create a file with any name in the directory `config/initializers/`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpassabilities%2Fbackrest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpassabilities%2Fbackrest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpassabilities%2Fbackrest/lists"}