{"id":15660407,"url":"https://github.com/softchris/yaml-server","last_synced_at":"2025-05-05T21:34:57.624Z","repository":{"id":40767743,"uuid":"265026916","full_name":"softchris/yaml-server","owner":"softchris","description":"a command line tool for creating a REST API server from a YAML file","archived":false,"fork":false,"pushed_at":"2023-01-24T02:36:33.000Z","size":622,"stargazers_count":20,"open_issues_count":18,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T23:51:14.535Z","etag":null,"topics":[],"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/softchris.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-18T18:30:49.000Z","updated_at":"2023-07-26T09:04:56.000Z","dependencies_parsed_at":"2023-02-05T12:32:17.251Z","dependency_job_id":null,"html_url":"https://github.com/softchris/yaml-server","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/softchris%2Fyaml-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softchris%2Fyaml-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softchris%2Fyaml-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softchris%2Fyaml-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softchris","download_url":"https://codeload.github.com/softchris/yaml-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251068513,"owners_count":21531480,"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":[],"created_at":"2024-10-03T13:21:33.137Z","updated_at":"2025-05-05T21:34:57.581Z","avatar_url":"https://github.com/softchris.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://dev.azure.com/devrel/chris-testing/_apis/build/status/softchris.yaml-server?branchName=master)](https://dev.azure.com/devrel/chris-testing/_build/latest?definitionId=23\u0026branchName=master)\n![Coverage](./badges/coverage.svg)\n[![npm version](https://badge.fury.io/js/yaml-server.svg)](https://www.npmjs.com/package/yaml-server)\n[![npm downloads](https://img.shields.io/npm/dm/yaml-server?color=blue\u0026label=npm%20downloads\u0026style=flat-square)](https://www.npmjs.com/package/yaml-server)\n[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?color=blue\u0026style=flat-square)](http://opensource.org/licenses/MIT)\n\n## Table of Contents\n\n- [About](#about)\n- [Features](#features)\n- [Install](#install)\n- [Run](#run)\n- [Routes](#routes)\n\n## About\n\nRecognition, this project wouldn't be here with out the great `json-server`. I thought to myself that JSON was a little verbose. So I created `yaml-server` so you can have a Mock REST API based on a YAML file instead.\n\n`yaml-server` is a command line tool that create a REST server based on a YAML file.\n\n![Application running](yaml-server.png)\n\n## Features\n\n- **RESTful API** Do HTTP requests towards a Mock API using GET, PUT, POST and DELETE created off of a `db.yml` file.\n- **Filter** your GET calls with query parameters `page` and `pageSize`, example:\n\n    ```bash\n    /products?page=1\u0026pageSize=10\n    ```\n\n- **JSON support**, yes you can have your database in JSON as well. All you need is to specify the `--dialect` argument like so:\n\n   ```bash\n   npx yaml-server --dialect=json\n   ```\n\n   The above will look after a `db.json` file at the root. You override where it looks for this if you specify `--database` like for example:\n\n   ```bash\n   npx yaml-server --dialect=json --database ./db/db.json\n   ```\n\n   Above you need to ensure the `db.json` is located in sub directory `db` as seen from the root.\n\n- **Create new resource**, make a POST call with the following format `/\u003cnew resource\u003e/new`, example:\n\n    ```bash\n    /kittens/new\n    ```\n\n    Ensure you have a payload as well, looking like for example `{ title: 'paw paw' }`\n\n- **Sorting, by order and key**, you can sort a resource response using query parameters `sortOrder` and `sortKey`. Assume we have the resource `/kittens` where one kitten object looks like so `{ id: 1, name: 'paws' }` and the entire resource looks like so:\n\n    ```javascript\n    [{\n      id: 1,\n      name: 'paws'\n    }, {\n      id: 2,\n      name: 'alpha paw'\n    }]\n    ```\n\n    Use sorting by appending `sortOrder` and `sortKey` like below:\n\n    ```bash\n    /kittens?sortOrder=ASC\u0026sortKey=name\n    ```\n\n    This would give the response:\n\n    ```javascript\n    [{\n      id: 2,\n      name: 'alpha paw'\n    }, {\n      id: 1,\n      name: 'paws'\n    }]\n    ```\n\n- **browser autostart**, the Browser auto starts at `http://locallhost:\u003cselected port\u003e/info`. Should you not wish to have that behavior, you can shut it off like so:\n\n   ```bash\n   npx yaml-server --autoStart=off\n   ```\n\n- **Static file server**\n\n  By default a static file server is starting up to host your files at root directory. You can change that by specifying `--static`. Here's how you would do that:\n\n   ```bash\n   npx yaml-server --static=public\n   ```\n\n   The above would start a static file server from the sub folder `public`.\n\n- **Hot reload**\n\n  The server will restart if you make changes to your database file. No need for closing and starting the server after a database change. Should you not wish that behavior, you can shut it off with:\n\n  ```bash\n  npx yaml-server --hotReload=off\n  ```\n\n## Install\n\nEither install it globally with:\n\n```bash\nnpm install -g yaml-server\n```\n\nOR use `NPX`\n\n```bash\nnpx yaml-server --port 3000 --database ./db.yml\n```\n\n## Run\n\n1. Create a `db.yml`.\n1. Give `db.yml` an example content, for example:\n\n   ```yaml\n   products:\n     - id: 1\n       name: tomato\n     - id: 2\n       name: lettuce\n   orders:\n    - id: 1\n      name: order1\n    - id: 2\n      name: order2\n   ```\n\n1. There are two ways to start:\n   1. **Quick start**, run `npx yaml-server`, this will start a server on `http://localhost:3000` and base it off a `db.yml` at the project root that you created.\n   1. **With parameters**, You can also configure like so `npx yaml-server --port 8000 --database ./db/mydb.yml` (If you place db file under `./db/mydb.yml`)\n\n### See your routes\n\nOpen up a browser and navigate to `http://localhost:\u003cyour port\u003e/info`. Default port is `3000`, if you specified port use that as port instead.\n\nThe page at route `http://localhost:\u003cport\u003e/info` will tell you what routes and operations are available. Here's a typical response for the default page:\n\n```output\nWelcome to YAML Server\n\nRoutes available are:\n\n GET /products\n GET /products/:id\n PUT /products\n DELETE /products/:id\n\n GET /orders\n GET /orders/:id\n PUT /orders\n DELETE /orders/:id\n```\n\n## Routes\n\nRoutes are created from a YAML file. The default value is  `db.yml`. You can name it whatever you want though.\n\nRoutes are first level elements. Consider the following example file:\n\n```yml\n# db.yml\nproducts:\n  - id: 1\n    name: tomato\n  - id: 2\n    name: lettuce\norders:\n  - id: 1\n    name: order1\n  - id: 2\n    name: order2\n```\n\nThis will produce routes `/products`, `/orders`. Below is a table of supported operations with `products` as example resource. The same operations are also supports for `orders/`.\n\n| VERB     |Route          | Input      | Output             |\n|----------|---------------|------------|--------------------|\n| GET      | /products     | *None*     | **Array**          |\n| GET      | /products/:id |  **e.g 3** | **Object**         |\n| POST     | /products     | **object** | **Created object** |\n| PUT      | /products     | **object** | **Updated object** |\n| DELETE   | /products/:id | **e.g 3**  | **Deleted object** |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftchris%2Fyaml-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftchris%2Fyaml-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftchris%2Fyaml-server/lists"}