{"id":13789588,"url":"https://github.com/OthmanAmoudi/Elysiajs-api-controllers","last_synced_at":"2025-05-12T07:30:49.108Z","repository":{"id":197687205,"uuid":"699115673","full_name":"OthmanAmoudi/Elysiajs-api-controllers","owner":"OthmanAmoudi","description":"Elysia RESTAPI with routing controllers and decorators ","archived":false,"fork":false,"pushed_at":"2023-10-07T23:44:38.000Z","size":168,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-19T00:41:18.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/OthmanAmoudi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-02T00:27:14.000Z","updated_at":"2024-07-28T11:31:06.410Z","dependencies_parsed_at":"2024-07-28T11:31:03.127Z","dependency_job_id":null,"html_url":"https://github.com/OthmanAmoudi/Elysiajs-api-controllers","commit_stats":null,"previous_names":["othmanamoudi/elysia-routing-controllers","othmanamoudi/elysiajs-api-controllers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OthmanAmoudi%2FElysiajs-api-controllers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OthmanAmoudi%2FElysiajs-api-controllers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OthmanAmoudi%2FElysiajs-api-controllers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OthmanAmoudi%2FElysiajs-api-controllers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OthmanAmoudi","download_url":"https://codeload.github.com/OthmanAmoudi/Elysiajs-api-controllers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253695023,"owners_count":21948800,"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-08-03T22:00:29.109Z","updated_at":"2025-05-12T07:30:48.801Z","avatar_url":"https://github.com/OthmanAmoudi.png","language":"TypeScript","funding_links":[],"categories":["Boilerplates"],"sub_categories":[],"readme":"# Elysia routing controllers\n\n### modular and concise template with decorators and services (inspired by nestjs)\n\n- Elysia RESTAPI starter example\n- Decorators for GET, POST, PUT and DELETE methods\n- Familiar middleware like express (beforeHandle)\n- by default, all requests are logged in the console ('GET -- /swagger -- 200 2023-10-02T00:48:20.857Z')\n- swagger included, everytime you register new controller,view all routes (http://localhost:3500/swagger)\n\nexample controller\n\n```ts\nimport { t } from 'Elysia';\nimport TasksService from './tasks.service';\nimport { AuthRoute } from '../../middlewares';\nimport { Delete, Get, Post, Put, BaseController } from '../../utils';\n\nlet TaskBody = t.Object({ title: t.String() });\nlet TaskResponse = t.Object({ id: t.Number(), title: t.String() });\nlet TaskListResponse = t.Array(TaskResponse);\nlet TaskParams = t.Object({ id: t.Numeric() });\nlet TaskQuery = t.Object({ limit: t.Optional(t.Numeric()) });\n\nclass TasksController extends BaseController {\n  routes = []; // step 1\n\n  constructor(public tasksService: TasksService) {\n    super('/tasks'); // step 2\n  }\n\n  @Get('/', { query: TaskQuery, response: TaskListResponse })\n  async index(ctx: any) {\n    return tasksService.getAllTasks(ctx.query.limit);\n  }\n\n  @Post('/', {\n    body: TaskBody,\n    response: TaskResponse,\n    beforeHandle: AuthRoute,\n  })\n  async create(ctx: any) {\n    return tasksService.createTask({ title: ctx.body.title });\n  }\n\n  @Get('/:id', { params: TaskParams, response: TaskResponse })\n  async show(ctx: any) {\n    return tasksService.getTask(ctx.params.id);\n  }\n\n  @Put('/:id', { params: TaskParams, body: TaskBody, response: TaskResponse })\n  async update(ctx: any) {\n    return tasksService.updateTask({\n      id: ctx.params.id,\n      title: ctx.body.title,\n    });\n  }\n\n  @Delete('/:id')\n  async destroy(ctx: any) {\n    return tasksService.deleteTask(Number(ctx.params.id));\n  }\n}\n\nconst tasksService = new TasksService();\n//step3\nexport default new TasksController(tasksService).start();\n//in server.ts add: app.use(TasksController)\n```\n\n## Create Turso db\n\n- make sure you already installed Turso CLI\n\n```sh\nturso db create mydatabasename\n```\n\nGet the db url\n\n```sh\nturso db show mydatabasename\n```\n\nGet the db token\n\n```sh\nturso db tokens create mydatabasename\n```\n\nUpdate the `.env` file with the token and url from the above commands\n\n```sh\nbun install\n```\n\n- if you want to switch to local sqlite [see this quide](https://orm.drizzle.team/docs/quick-sqlite/bun)\n\n## Run the application\n\nTo start the development server run:\n\n```sh\nnpm run dev\n```\n\nOpen http://localhost:3500/ with your browser to see the result.\n\nmake sure in your tsconfig.json you have:\n\n```\n\"experimentalDecorators\": true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOthmanAmoudi%2FElysiajs-api-controllers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOthmanAmoudi%2FElysiajs-api-controllers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOthmanAmoudi%2FElysiajs-api-controllers/lists"}