{"id":19124385,"url":"https://github.com/glorious-codes/glorious-crud","last_synced_at":"2025-05-05T19:21:17.690Z","repository":{"id":57113577,"uuid":"131295369","full_name":"glorious-codes/glorious-crud","owner":"glorious-codes","description":"A bare minimum and extensible crud generator","archived":false,"fork":false,"pushed_at":"2019-05-05T19:43:38.000Z","size":161,"stargazers_count":45,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-03T17:02:44.948Z","etag":null,"topics":["crud-generator","expressjs","javascript","mongodb","nodejs"],"latest_commit_sha":null,"homepage":"https://glorious.codes/crud","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glorious-codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-27T12:44:51.000Z","updated_at":"2024-09-26T00:59:29.000Z","dependencies_parsed_at":"2022-09-01T06:30:21.296Z","dependency_job_id":null,"html_url":"https://github.com/glorious-codes/glorious-crud","commit_stats":null,"previous_names":["rafaelcamargo/glorious-crud"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glorious-codes%2Fglorious-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glorious-codes%2Fglorious-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glorious-codes%2Fglorious-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glorious-codes%2Fglorious-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glorious-codes","download_url":"https://codeload.github.com/glorious-codes/glorious-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223789855,"owners_count":17203267,"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":["crud-generator","expressjs","javascript","mongodb","nodejs"],"created_at":"2024-11-09T05:28:58.034Z","updated_at":"2024-11-09T05:28:58.126Z","avatar_url":"https://github.com/glorious-codes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Glorious Crud\n\n\u003e A bare minimum and extensible crud generator.\n\n[![CircleCI](https://circleci.com/gh/glorious-codes/glorious-crud/tree/master.svg?style=svg)](https://circleci.com/gh/glorious-codes/glorious-crud/tree/master)\n[![codecov](https://codecov.io/gh/glorious-codes/glorious-crud/branch/master/graph/badge.svg)](https://codecov.io/gh/rafaelcamargo/glorious-crud)\n\n## Installation\n\n```\nnpm install @glorious/crud --save\n```\n\n## Usage\n\n### Basic\n\nThe purpose of this lib is to remove all the effort involved in creating a default crud as well as keeping everything under your control through its options.\n\n``` javascript\nconst express = require('express');\nconst GCrud = require('@glorious/crud');\n\nconst app = express();\nconst gCrud = new GCrud('databaseUrl', 'databaseName', app);\n\n// The line below will make the following endpoints available:\n// GET    /beers\n// GET    /beers/:id\n// POST   /beers\n// PUT    /beers/:id\n// DELETE /beers/:id\nconst beersResource = gCrud.build('beers');\n\n// From here, you can add any other custom endpoint you need.\nbeersResource.get('/beers/:id/awards', (req, res) =\u003e {\n  // Your specific needs go here.\n});\n\napp.listen(9000, () =\u003e {\n  console.log(`Running on port 9000...`);\n});\n\n```\n\n### Options\n\nUsing options, you can override any method by doing as follows:\n\n``` javascript\nconst options = {\n  get: (req, res) =\u003e {\n    // This implementation will override get method.\n    // The same can be done for any other method:\n    // post, put, delete.\n  }\n}\n\nconst beersResource = gCrud.build('beers', options);\n```\n\nYou can also set listeners to be called *on success* or *on error* of some method:\n``` javascript\nconst options = {\n  // Executes after every successful get request\n  onGetSuccess: (req, res, response) =\u003e {\n    // response is an object containing \"status\" (200) and \"body\".\n  },\n  // Executes after every failed get request\n  onGetError: (req, res, err) =\u003e {\n    // err is an object containing \"status\" (4xx or 5xx) and \"body\".\n  },\n  // Executes after every successful post request\n  onPostSuccess: (req, res, response) =\u003e {\n    // response is an object containing \"status\" (201) and \"body\".\n  },\n  // Executes after every failed post request\n  onPostError: (req, res, err) =\u003e {\n    // err is an object containing \"status\" (4xx or 5xx) and \"body\".\n  },\n  // Executes after every successful put request\n  onPutSuccess: (req, res, response) =\u003e {\n    // response is an object containing \"status\" (204).\n  },\n  // Executes after every failed put request\n  onPutError: (req, res, err) =\u003e {\n    // err is an object containing \"status\" (4xx or 5xx) and \"body\".\n  },\n  // Executes after every successful delete request\n  onDeleteSuccess: (req, res, response) =\u003e {\n    // response is an object containing \"status\" (204).\n  }\n  // Executes after every failed delete request\n  onDeleteError: (req, res, err) =\u003e {\n    // err is an object containing \"status\" (4xx or 5xx) and \"body\".\n  }\n}\n\nconst beersResource = gCrud.build('beers', options);\n```\n\n### Built-in Query Params\n\nWhen querying resources, you can use some built-in query params:\n\n#### $sortBy\n\nSort some collection by one of its attributes:\n\n```\ncurl http://localhost:9000/beers?$sortBy=name\n```\n\n#### $order\n\nOrder a sorted request by `asc` or `desc`:\n\n```\ncurl http://localhost:9000/beers?$sortBy=name\u0026$order=desc\n```\n\n#### $limit\n\nLimit the number of results:\n\n```\ncurl http://localhost:9000/beers?$limit=1\n```\n\nAlso, you can use any resource attribute name as a filter:\n\n```\ncurl http://localhost:9000/beers?name=Opa%20Bier\n```\n\n## Contributing\n\n1. Install [Node](https://nodejs.org/en/). Download the \"Recommend for Most Users\" version.\n\n2. Clone the repo:\n``` bash\ngit clone git@github.com:glorious-codes/glorious-crud.git\n```\n\n3. Go to the project directory\n``` bash\ncd glorious-crud\n```\n\n4. Install the project dependencies\n``` bash\nnpm install\n```\n\n6. run:\n``` bash\nnode src/app.js\n```\n\n7. The API will be running on `http://localhost:9000`.\n\n8. Make some request to see the API in action:\n``` bash\ncurl http://localhost:9000/beers \\\n  -H 'content-type: application/json' \\\n  -d '{ \"name\":\"Opa Bier\" }'\n```\n\n**NOTE**\nCheck out below how to configure MongoDB on your machine before making any request to the API.\n\n## Database\n\n1. Install MongoDB following its website [instructions](https://docs.mongodb.com/manual/administration/install-community/).\n\n2. Create a database called `gcrud`.\n\n3. Create a collection called `beers`.\n\n4. Start mongo on the default port(27017): Type `mongod` on your terminal.\n\n## Tools\n\n1. [Postman](https://www.getpostman.com/) is an awesome tool that makes API development a breeze.\n\n2. [MongoDB Compass](https://www.mongodb.com/products/compass) is the prettiest MongoDB UI client I have ever seen.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglorious-codes%2Fglorious-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglorious-codes%2Fglorious-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglorious-codes%2Fglorious-crud/lists"}