{"id":19589100,"url":"https://github.com/popcorn-official/pop-api","last_synced_at":"2025-04-27T12:32:05.611Z","repository":{"id":57327397,"uuid":"112380393","full_name":"popcorn-official/pop-api","owner":"popcorn-official","description":"The base modules for popcorn-api","archived":false,"fork":false,"pushed_at":"2018-05-08T10:32:35.000Z","size":974,"stargazers_count":10,"open_issues_count":1,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-07T06:19:42.715Z","etag":null,"topics":["express","mongoose","popcorn","popcorn-api","popcorn-time"],"latest_commit_sha":null,"homepage":"https://popcorn-official.github.io/pop-api/manual/index.html","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/popcorn-official.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-28T19:37:50.000Z","updated_at":"2022-12-07T10:11:26.000Z","dependencies_parsed_at":"2022-09-13T19:22:05.579Z","dependency_job_id":null,"html_url":"https://github.com/popcorn-official/pop-api","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popcorn-official%2Fpop-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popcorn-official%2Fpop-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popcorn-official%2Fpop-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/popcorn-official%2Fpop-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/popcorn-official","download_url":"https://codeload.github.com/popcorn-official/pop-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224069362,"owners_count":17250456,"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","mongoose","popcorn","popcorn-api","popcorn-time"],"created_at":"2024-11-11T08:17:06.813Z","updated_at":"2024-11-11T08:17:08.467Z","avatar_url":"https://github.com/popcorn-official.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pop-api\n\n[![Build Status](https://travis-ci.org/popcorn-official/pop-api.svg?branch=master)](https://travis-ci.org/popcorn-official/pop-api)\n[![Windows Build](https://img.shields.io/appveyor/ci/chrisalderson/pop-api/master.svg?label=windows)](https://ci.appveyor.com/project/ChrisAlderson/pop-api)\n[![Coverage Status](https://coveralls.io/repos/github/popcorn-official/pop-api/badge.svg?branch=master)](https://coveralls.io/github/popcorn-official/pop-api?branch=master)\n[![Dependency Status](https://david-dm.org/popcorn-official/pop-api.svg)](https://david-dm.org/popcorn-official/pop-api)\n[![devDependencies Status](https://david-dm.org/popcorn-official/pop-api/dev-status.svg)](https://david-dm.org/popcorn-official/pop-api?type=dev)\n\n## Features\n\nThe pop-api project aims to provide the core modules for the\n[`popcorn-api`](https://github.com/popcorn-official/popcorn-api) project, but\ncan also be used for other purposes by using middleware.\n - Cli middleware for reading user input with [`commander.js`](https://github.com/tj/commander.js).\n - Database middleware for connection to MongoDB through [`mongoose`](https://github.com/Automattic/mongoose).\n - Logging of routes and other information using [`winston`](https://github.com/winstonjs/winston).\n - Uses [`express`](https://github.com/expressjs/express) under the hood with:\n   - Body middleware with [`body-parser`](https://github.com/expressjs/body-parser)\n   - Error handling\n   - Security middleware with [`helmet`](https://github.com/helmetjs/helmet)\n - Interface for registering routes for [`express`](https://github.com/expressjs/express).\n - Data Access Layer (DAL) class for standard CRUD operations.\n - Route controller to handle routes for your content.\n\n## Installation\n\n```\n $ npm install --save pop-api\n```\n\n## Documentation\n\n - [General documentation](https://popcorn-official.github.io/pop-api/manual/index.html)\n - [Api docs](https://popcorn-official.github.io/pop-api/identifiers.html)\n - [Usage](https://popcorn-official.github.io/pop-api/manual/usage.html) \n - [Middleware](https://popcorn-official.github.io/pop-api/manual/middleware.html) \n - [Advanced Usage](https://popcorn-official.github.io/pop-api/manual/advanced.html) \n - [Extending Middleware](https://popcorn-official.github.io/pop-api/manual/extending-middleware.html) \n\n## Usage\n\nFor your basic setup you have to create a controller which will handle the\nroutes. Your controller needs to extend from the `IController` interface to\nimplement the `registerRoutes` method which will be called during the setup.\n\nThe route controller below will be created with a constructor which takes an\nobject as the parameter. This example will register a `GET /hello` route and\nsends a JSON object as a response with a greeting to the name provided by the\nobject from the constructor.\n\n```js\n// ./MyRouteController.js\nimport { IController } from 'pop-api'\n\n// Extend your route controller from the 'IController' interface.\nexport default class MyRouteController extends IController {\n\n  // The constructor takes an object as the parameter.\n  constructor({name}) {\n    super()\n\n    this.name = name\n  }\n\n  // Implement the 'registerRoutes' method from the 'IController interface.\n  registerRoutes(router, PopApi) {\n    router.get('/hello', this.getHello.bind(this))\n  }\n\n  // Router middleware to execute on the 'GET /hello' route.\n  getHello(req, res, next) {\n    return res.json({\n      message: `Hello, ${this.name}`\n    })\n  }\n\n}\n```\n\nTo initialize the API we create an array of the route controllers and their\nconstructor arguments we want to register. Then we just call the `init` method\nwith the route controllers array, and the name and version your API (needed for\nthe Cli). The API should run by default on port `5000`.\n\n```js\n// ./index.js\nimport { PopApi } from 'pop-api'\nimport MyRouteController from './MyRouteController'\nimport { name, version } from './package.json'\n\n;(async () =\u003e {\n  try {\n    // Define the controllers you want to use.\n    const controllers = [{\n      Controller: MyRouteController,  // The controller to register.\n      args: {                         // The arguments passed down to the\n        name: 'John'                  // The additional arguments to pass to\n                                      // your route controller.\n      }\n    }]\n\n    // Initiate your API with the necessary parameters.\n    await PopApi.init({                \n      controllers,  // The controllers to register.\n      name,         // The name of your API.\n      version       // The version of your API.\n    })\n    // API is available on port 5000.\n    // GET http://localhost:5000/hello -\u003e { message: 'Hello, John' }\n  } catch (err) {\n    console.log(err)\n  }\n})()\n```\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpopcorn-official%2Fpop-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpopcorn-official%2Fpop-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpopcorn-official%2Fpop-api/lists"}