{"id":15617004,"url":"https://github.com/saibotsivad/glopen-routes","last_synced_at":"2026-04-25T11:33:55.370Z","repository":{"id":46220113,"uuid":"421193870","full_name":"saibotsivad/glopen-routes","owner":"saibotsivad","description":"Some common routes that I find myself needing often, in glopen format.","archived":false,"fork":false,"pushed_at":"2021-11-24T18:45:35.000Z","size":624,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T05:34:52.378Z","etag":null,"topics":["api","glopen","openapi"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saibotsivad.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-25T21:45:51.000Z","updated_at":"2021-11-24T18:45:32.000Z","dependencies_parsed_at":"2022-09-26T18:30:26.898Z","dependency_job_id":null,"html_url":"https://github.com/saibotsivad/glopen-routes","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/saibotsivad/glopen-routes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saibotsivad%2Fglopen-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saibotsivad%2Fglopen-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saibotsivad%2Fglopen-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saibotsivad%2Fglopen-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saibotsivad","download_url":"https://codeload.github.com/saibotsivad/glopen-routes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saibotsivad%2Fglopen-routes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32261116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","glopen","openapi"],"created_at":"2024-10-03T07:40:50.270Z","updated_at":"2026-04-25T11:33:50.362Z","avatar_url":"https://github.com/saibotsivad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Glopen Routes\n\nSome common routes that I find myself needing often, in [glopen](https://github.com/saibotsivad/glopen) format, with [JSON:API](https://jsonapi.org/) schemas.\n\n[See the list of route definitions and their functionality.](./definition/README.md)\n\n## Install\n\nThe usual way:\n\n```shell\nnpm install @saibotsivad/glopen-routes\n```\n\nTo use with `glopen`, you can either include everything in one go, grab individual definitions, or explicitly grab each Operation Object.\n\n(Each definition has an `openapi` folder or a `routes` folder, or both. The `routes` folder separates the Operation Objects out, so they can be explicitly grabbed and still allow merging in the other `openapi` parts. See below for a detailed explanation.)\n\n### Everything At Once\n\nYou can use the exported convenience function, which returns a list of all the definitions, ready for use by `glopen`:\n\n```js\n// glopen.config.js\nimport { all } from '@saibotsivad/glopen-routes'\nexport default {\n\tmerge: [\n\t\t...all({\n\t\t\t// Optional: apply the `api` option to all routes.\n\t\t\tapi: '/api/v1'\n\t\t})\n\t]\n}\n```\n\nIf you want everything else but don't need team support, you can use `allNoTeams` instead of `all`.\n\n```js\n// glopen.config.js\nimport { allNoTeams } from '@saibotsivad/glopen-routes'\nexport default {\n\tmerge: [\n\t\t...allNoTeams({\n\t\t\t// Optional: apply the `api` option to all routes.\n\t\t\tapi: '/api/v1'\n\t\t})\n\t]\n}\n```\n\n### Individual Definitions\n\nEach definition is a set of interdependent routes, and each is exported as a named function e.g. `singleUser`. See the [full list for details](./definition/README.md).\n\nYou will also need to merge in the [shared items](./definition/_shared), which are shared across all routes.\n\nFor example, the routes for a single user to manage their own self:\n\n```js\n// glopen.config.js\nimport { shared, singleUser } from '@saibotsivad/glopen-routes'\nexport default {\n\tmerge: [\n\t\t// The shared components are always required\n\t\t...shared(),\n\t\t// Then each definition\n\t\t...singleUser({\n\t\t\t// The definitions can have their API path prefix set\n\t\t\tapi: '/api/v1'\n\t\t})\n\t],\n}\n```\n\n### Explicit Import\n\nIf you want to be explicit about each Operation Object that you bring in to your project, or if you want to rename the paths entirely, you can create a file and import-\u003eexport the route, overwriting the bits that you want.\n\nFor example: if you simply want to rename `GET /user` to `GET /currentUser` you could create a folder structure in your project which you would point [glopen](https://github.com/saibotsivad/glopen) to, then create the file like so:\n\n```js\n// \u003cYOUR_ROUTES\u003e/currentUser/get.@.js\n// First: re-export all the named exports\nexport * from '@saibotsivad/glopen-routes/definition/basic-user-auth/routes/paths/user/get.@.js'\n// Second: re-export the default, which is the route handler\nexport { default } from '@saibotsivad/glopen-routes/definition/basic-user-auth/routes/paths/user/get.@.js'\n```\n\nAdditional example: if you also want to customize the `security` and `tags` for each:\n\n```js\n// \u003cYOUR_ROUTES\u003e/currentUser/get.@.js\n// First: re-export all the named exports\nexport * from '@saibotsivad/glopen-routes/definition/basic-user-auth/routes/paths/user/get.@.js'\n// Second: re-export the default, which is the route handler\nexport { default } from '@saibotsivad/glopen-routes/definition/basic-user-auth/routes/paths/user/get.@.js'\n// Third: exporting `security` here will overwrite whatever was re-exported in the first step\nexport const security = [ { myBetterAuth: [] } ]\n// Fourth: in the same way, exporting `tags` would completely overwrite the re-exported\n// tags list. If you want to *merge* the lists, you'll need to import it explicitly, and\n// then export the merged list\nimport { tags as tagsList } from '@saibotsivad/glopen-routes/definition/basic-user-auth/routes/paths/user/get.@.js'\nexport const tags = [ ...tagsList, 'my-custom-tag' ]\n```\n\n**Note:** in your `glopen` config file you'd still need to merge in the shared components and the `openapi` folder for the named definition:\n\n```js\n// glopen.config.js\nexport default {\n\tmerge: [\n\t\t// The shared definition parts are always required\n\t\t{ dir: './node_modules/@saibotsivad/glopen-routes/definition/_shared/openapi' },\n\t\t// For the explicit imported routes, you need to include the `openapi` part\n\t\t// to get the component schemas\n\t\t{ dir: './node_modules/@saibotsivad/glopen-routes/definition/basic-user-auth/openapi' },\n\t\t// Finally, merge in your own project routes\n\t\t{ dir: '\u003cYOUR_ROUTES\u003e' },\n\t],\n}\n```\n\nUsing this approach can be a bit tedious, since you would need to recreate the folder structure for all route methods, e.g. in the `basic-user-auth` there are at least ten (10) files, and you'd need to create all ten in order to have all functionality explicitly named.\n\nOne shortcut to note is that `glopen` will merge first-to-last, so as long as you aren't *renaming* any files, you could be explicit with one or two Operation Objects, then merge the named definition first and your explicit folder last, and yours would end up overwriting the original.\n\n## Design\n\nThe route handlers are async and take a request object with a properties that need to be initialized prior to executing the handler function:\n\n- `body: Object` - The request body for all these routes is JSON so, for routes that need it, you'll need a body-parser that parses the JSON in advance.\n- `controller: Object` - The set of initialized controllers, which are essentially the functions that do the actual work, like `user.create`. (Each route lists the controllers it requires.)\n\nInstead of setting properties on a response object, like Express etc., these route handlers return an object with the following properties:\n\n- `status: Number` - The response status code.\n- `headers: Object` - These headers should be merged with any other headers, overwriting base headers if any exist.\n- `body: Object | String | null` - The response body, if it exists.\n- `json: Boolean` - The response `body` must be passed through a JSON stringify function prior to being returned.\n\nHere is a little demo to show you how you might instantiate and handle a request:\n\n```js\n// You'll need to instantiate controllers in advance (or use lazy instantiation techniques).\nconst controller = {\n\tdemo: {\n\t\tgetDemo: async (request) =\u003e {\n\t\t\tif (request.headers['X-API-Token'] === 'battery-horse-staple') {\n\t\t\t\treturn [ 'first', 'second' ]\n\t\t\t} else {\n\t\t\t\treturn [ 'third', 'fourth' ]\n\t\t\t}\n\t\t}\n\t}\n}\n// This is what one of the handlers from this project might look like.\nconst demoRequestHandler = async request =\u003e {\n\t// The controllers are assumed to be instantiated already.\n\tconst data = await request.controller.demo.getDemo(request)\n\treturn {\n\t\tstatus: 200,\n\t\tjson: true,\n\t\tbody: { data }\n\t}\n}\n// This is a very naive approach, but shows the fundamentals.\nimport http from 'http'\nconst server = http.createServer((request, response) =\u003e {\n\trequest.controller = controller\n\tdemoRequestHandler(request).then(({ status, json, body }) =\u003e {\n\t\tresponse.statusCode = status\n\t\tif (json) {\n\t\t\tresponse.setHeader('Content-Type', 'application/json')\n\t\t\tresponse.end(JSON.stringify(body))\n\t\t} else {\n\t\t\tresponse.end(body)\n\t\t}\n\t})\n})\n```\n\n## License\n\nPublished and released under the [Very Open License](http://veryopenlicense.com).\n\nIf you need a commercial license, [contact me here](https://davistobias.com/license?software=glopen-routes).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaibotsivad%2Fglopen-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaibotsivad%2Fglopen-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaibotsivad%2Fglopen-routes/lists"}