<commit_before># Backrest

Rails like Node framework to create simple, pure backend APIs.

[![npm](https://img.shields.io/npm/v/backrest.svg)](https://www.npmjs.com/package/backrest)

## CLI

### Install

`npm i backrest -g`

### Usage

```
 ❯ backrest help

  Usage: backrest [options] [command]


  Commands:

    init|i <name>  create blank Backrest template
    start|s        start the server
    stop           stop the server
    help [cmd]     display help for [cmd]

  Options:

    -h, --help  output usage information
```

### Development

Start the project and watch for file changes.

`backrest s -w`

### Production

Start the project in a background process.

`NODE_ENV=production backrest s -d`

To stop:

`backrest stop`

## Package Module

This project uses [ExpressJS](http://expressjs.com/) behind the scenes. Please visit their website to have a better understanding of how routing and requests work.

### Routing

Creating routes are meant to be easy with a very simple structure.

Routes are defined in `config/routes.js`

Each route will need a couple things:

* An action verb
* URL end point
* Controller name
* Action name

The layout of each route will be in the following format:

* `'{verb} {url}': '{controller}#{action}'`
* **verb**
  * `get`, `post`, `put`, or `delete`
* **url**
  * URL end point that begins at root (leading `/` is optional)
  * URLs are allowed to have parameters defined denoted using a colon (`:`)
    * Example: `users/:id`
* **controller**
  * The controller name is the prefix of the file it is defined in. For example you would use `users` for the controller `app/controllers/users_controller.js`
* **action**
  * This is the name of the function to call defined in the controller.

There are a couple ways to define how routes work:

1. All inline:

  `'get users/all': 'users#getAll'`

1. Nested:

  ```javascript
    'users': {
      'get all': 'users#getAll'
    }
  ```

1. Exclude controller name:

  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:
  ```javascript
    'get users/all': 'getAll',
    'users': {
      'get all': 'getAll'
    }
  ```<commit_msg>Update README with new routes definition.<commit_after># Backrest

Rails like Node framework to create simple, pure backend APIs.

[![npm](https://img.shields.io/npm/v/backrest.svg)](https://www.npmjs.com/package/backrest)

## CLI

### Install

`npm i backrest -g`

### Usage

```
 ❯ backrest help

  Usage: backrest [options] [command]


  Commands:

    init|i <name>  create blank Backrest template
    start|s        start the server
    stop           stop the server
    help [cmd]     display help for [cmd]

  Options:

    -h, --help  output usage information
```

### Development

Start the project and watch for file changes.

`backrest s -w`

### Production

Start the project in a background process.

`NODE_ENV=production backrest s -d`

To stop:

`backrest stop`

## Package Module

This project uses [ExpressJS](http://expressjs.com/) behind the scenes. Please visit their website to have a better understanding of how routing and requests work.

### Routing

Creating routes are meant to be easy with a very simple structure. They are defined using an array format to allow defining route precedence. Former routes will take precedence over latter ones if they both match the requested URL.

Location: `config/routes.js`

Each route will need a couple things:

* An action verb
* URL end point
* Controller name
* Action name

The layout of each route will be in the following format:

* `['{verb} {url}', '{controller}#{action}']`
* **verb**
  * `get`, `post`, `put`, or `delete`
* **url**
  * URL end point that begins at root (leading `/` is optional)
  * URLs are allowed to have parameters defined denoted using a colon (`:`)
    * Example: `users/:id`
* **controller**
  * The controller name is the prefix of the file it is defined in. For example you would use `users` for the controller `app/controllers/users_controller.js`
* **action**
  * This is the name of the function to call defined in the controller.

There are a couple ways to define how routes work:

1. All inline:

  ```javascript
    module.exports = [
      ['get users/all', 'users#getAll']
    ]
  ```

1. Nested:

  ```javascript
    module.exports = [
      ['users', [
        ['get all', 'users#getAll']
      ]]
    ]
  ```

1. Exclude controller name:

  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:
  ```javascript
    module.exports = [
      ['get users/all', 'getAll'],
      ['users', [
        ['get all', 'getAll']
      ]]
    ]
  ```
{'fraction_non_alphanumeric': 0.11231732776617954, 'fraction_numerical': 0.0012526096033402922, 'mean_word_length': 3.3007181328545783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '845689', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1406, 'n_words': 609}