{"id":22468505,"url":"https://github.com/projectweekend/express-classy","last_synced_at":"2025-03-27T15:44:36.033Z","repository":{"id":29157199,"uuid":"32687526","full_name":"projectweekend/express-classy","owner":"projectweekend","description":"A set of classy route handlers","archived":false,"fork":false,"pushed_at":"2015-04-11T15:46:32.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T19:29:44.626Z","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/projectweekend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-22T17:54:43.000Z","updated_at":"2015-04-11T15:46:33.000Z","dependencies_parsed_at":"2022-08-02T21:34:15.268Z","dependency_job_id":null,"html_url":"https://github.com/projectweekend/express-classy","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/projectweekend%2Fexpress-classy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fexpress-classy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fexpress-classy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fexpress-classy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectweekend","download_url":"https://codeload.github.com/projectweekend/express-classy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245874188,"owners_count":20686722,"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-12-06T11:17:00.237Z","updated_at":"2025-03-27T15:44:36.007Z","avatar_url":"https://github.com/projectweekend.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"After building quite a few APIs with Node.js and Express over the last couple years, I started forming some strong opinions about what I liked and disliked. I had gotten very familiar with the [async](https://github.com/caolan/async) library, and rightly so. It's a great tool for maintaining control in the face of all those callbacks. However, I was always left wanting something that felt a little more structured. I wanted a pattern, something I could lean on to standardize the way I do things. Since API routes have common high-level components (validating a request, performing an action in the database, returning a response, etc), `express-classy` is my take on organizing and controlling the logic flow in Express route handlers.\n\n\n## Example\n\n**add_person.js:**\n\n```javascript\nvar util = require( \"util\" );\nvar CreateHandler = require( \"express-classy\" ).CreateHandler;\n\n\nmodule.exports = AddPerson;\n\n\nfunction AddPerson () {\n    CreateHandler.call( this );\n}\n\nutil.inherits( AddPerson, CreateHandler );\n\nAddPerson.prototype.validate = function() {\n\n    this.req.checkBody( \"firstName\", \"'firstName' is required\" ).isLength( 1 );\n    this.req.checkBody( \"lastName\", \"'lastName' is required\" ).isLength( 1 );\n\n    var validationErrors = this.req.validationErrors();\n\n    if ( validationErrors ) {\n        return this.emit( \"invalid\", validationErrors );\n    }\n\n    var person = {\n        firstName: this.req.body.firstName,\n        lastName: this.req.body.lastName\n    };\n\n    return this.emit( \"create\", person );\n\n};\n\nAddPerson.prototype.action = function( person ) {\n\n    // add 'person' to the database here\n    // if error, emit \"error\", passing the error\n    // if successful, emit \"done\", passing the data for response\n\n};\n```\n\n**routes.js:**\n\n```javascript\nvar express = require( \"express\" );\nvar router = express.Router();\nvar AddPerson = require( \"./add_person\" );\n\n\nvar addPerson = new AddPerson();\nrouter.post( \"/person\", function ( req, res, next ) {\n    addPerson.handle( req, res, next );\n} );\n\n\nmodule.exports = router;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fexpress-classy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectweekend%2Fexpress-classy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fexpress-classy/lists"}