{"id":19614385,"url":"https://github.com/samuelscheit/lambert-server","last_synced_at":"2025-06-12T07:08:18.086Z","repository":{"id":46402843,"uuid":"326695434","full_name":"SamuelScheit/Lambert-server","owner":"SamuelScheit","description":"An express.js route handler","archived":false,"fork":false,"pushed_at":"2024-12-07T19:40:22.000Z","size":135,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-23T20:09:59.661Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/SamuelScheit.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-04T13:37:36.000Z","updated_at":"2024-12-07T19:40:19.000Z","dependencies_parsed_at":"2024-06-19T16:23:39.565Z","dependency_job_id":"321f383c-e525-4a16-8b4e-5b28e5a5fdc1","html_url":"https://github.com/SamuelScheit/Lambert-server","commit_stats":null,"previous_names":["trenite/lambert-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SamuelScheit/Lambert-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamuelScheit","download_url":"https://codeload.github.com/SamuelScheit/Lambert-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259418186,"owners_count":22854184,"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-11-11T10:51:52.385Z","updated_at":"2025-06-12T07:08:18.043Z","avatar_url":"https://github.com/SamuelScheit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambert-server\nAn express.js Route Handler\n\n## Installation\n```\nnpm i lambert-server\n```\n\n## Usage\nES5 Import\n```js\nconst { Server, HTTPError } = require(\"lambert-server\");\n```\n\nor ES6 Import\n```ts\nimport { Server, HTTPError } from \"lambert-server\"\n```\n\n## Server\nServer options:\n```ts\nconst server = new Server({\n\tport        : number  = 8080;       // the port to listen on\n\thost        : string  = \"0.0.0.0\";  // the interface to listen on\n\tproduction  : boolean = false;      // enable in production mode - this will hide internal server errors\n\tserverInitLogging: boolean = true; // allows the server to log informations at startup, errors are excluded from this option\n\terrorHandler: (err: Error, req: Request, res: Response, next: NextFunction) =\u003e void // Default error handler displays JSON errors\n})\n```\nTo access the express [app](https://expressjs.com/de/4x/api.html#app) manually use ``server.app``\n\n## Register Routes\n```ts\nserver.registerRoutes(root: string): Promise\u003cany[]\u003e; // root is the root directory of all routes\n```\nThe HTTP API path is generated automatically based on the folder structure, so it is important that you name your files accordingly.\n\n\n\n## Body checking\nJSON body can be checked with a schema, that you pass to the check function.\nA Schema is a Object Structure with key-value objects that checks if the key is an instance of the value (class).\nYou can specify optional parameters if you prefix the key with a $\ne.g.: ``{ $captcha: String }``, this will make the ``captcha`` property in the body optional.\n```js\nimport { check } from \"lambert-server\";\nconst SCHEMA = { username: String, age: Number, $posts: [{ title: String }] }\napp.post(\"/\", check(SCHEMA), (req, res) =\u003e {});\n```\n\n## Examples\n### Example Server\nIn /index.js\n```ts\nimport { Server } from \"lambert-server\";\n// const { Server } = require(\"lambert-server\");\n\nasync function main() {\n\tconst server = new Server();\n\tawait server.registerRoutes(__dirname + \"/routes/\");\n\tawait server.start();\n}\n\nmain().catch(console.error)\n```\n\n## Example Route\nIn /routes/index.js\n```js\nimport { Router } from \"express\";\nimport { HTTPError, check } from \"lambert-server\";\n// const { Router } = require(\"express\")\n// const { HTTPError, check } = require(\"lambert-server\")\n\nconst router = Router();\n\nrouter.get(\"/\", (req, res) =\u003e {\n\tres.send(\"Hello World\");\n});\n\nrouter.get(\"/test\", (req, res) =\u003e {\n\tthrow new HTTPError(\"You don't have access to this ressource\", 401);\n});\n \n// JSON body parser\nrouter.post(\"/\", check({ username: String, age: Number, $posts: [{ title: String }] }), (req, res) =\u003e {});\n\nexport default router;\n// module.exports = router\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelscheit%2Flambert-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelscheit%2Flambert-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelscheit%2Flambert-server/lists"}