{"id":24132843,"url":"https://github.com/formcms/typeorm-json-api","last_synced_at":"2026-03-07T08:02:47.609Z","repository":{"id":57383635,"uuid":"298816120","full_name":"formcms/typeorm-json-api","owner":"formcms","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-24T00:34:26.000Z","size":218,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-30T01:46:19.015Z","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":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formcms.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":"2020-09-26T13:06:45.000Z","updated_at":"2025-11-24T06:10:15.000Z","dependencies_parsed_at":"2022-09-14T00:21:21.711Z","dependency_job_id":null,"html_url":"https://github.com/formcms/typeorm-json-api","commit_stats":null,"previous_names":["jaikechen/typeorm-json-api","formcms/typeorm-json-api","fluent-cms/typeorm-json-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/formcms/typeorm-json-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formcms%2Ftypeorm-json-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formcms%2Ftypeorm-json-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formcms%2Ftypeorm-json-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formcms%2Ftypeorm-json-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formcms","download_url":"https://codeload.github.com/formcms/typeorm-json-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formcms%2Ftypeorm-json-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30209796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"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":[],"created_at":"2025-01-11T22:38:35.398Z","updated_at":"2026-03-07T08:02:47.584Z","avatar_url":"https://github.com/formcms.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# why this lib\n## this is a generic web api router which can CRUD(create, read, update, delete) any TypeOrm entities\n``` typescript\n- query records: get /api/repos/yourEntity \n- query by id: get /api/repos/yourEntity/:id\n- add a records: post /api/repos/yourEntity\n- modify a record: put /api/repos/yourEntity/:id\n- delete a records: /api/repos/yourEntity/:id\n```\n\n## with query parameters, the get/read api supports\n- pagination\n- filter on each field \n- order on each field\n\n## support role based authorization, if you want some entity only accessed by  admin role, simply add\n``` typescript\n@Entity()\n@Authorize({role:'admin'}\nexport class User {\n    @PrimaryGeneratedColumn()\n    id: number\n}\n```\n## you can also add authorization to specific operations, for example you want common use only be able to delete his how post, \n```typescript\n@Authorize({role:'common', operation:'delete', columns:['userId']})\n``` \n\n\n# query parameters usage\nsuppose you have a entity user as following:\n```typescript\n{id:number, firstName:number, lastName:number}\n```\n## get /api/repos/user\nif the client request the api without parameter, the api will return all users\n## get  api/repos/user?s=3\u0026c=2 \n- key 's' - how many records should skip\n- key 'c' - how many records should return \n- so this example skips the first 3 records, takes 2 records: \n## get api/repos/user?firstName=a\n- the key firstName means field name\n- 'a' and 'd' are two reserved values, 'a' means order by user asc, 'd' means order by user desc\n- so this example return all users, order by firstName asc\n## api/repos/user?firstName=*Joe\n- query the users whose firstName contains 'Joe', \n```sql\nfirstName like '%Joe%'\n```\n## api/repos/user?firstName=Joe\n- query the users whose firstName exactly match 'Joe'\n```sql\nfirstName = 'Joe'\n```\n## api/repos/user?id=2~4\n- find user id range from 2 to 4\u003cbr/\u003e\n```sql\nfirstName between (2,4)\n```\n## api/repos/user?id=2~\n- find user id \u003e= 2 \u003cbr/\u003e\n## api/repos/user?id=~4\n- find user id \u003c= 4\n\n# installation\n## if you are starting a new project,\n you can clone https://github.com/jaikechen/typeorm-json-api/tree/master/src/app as an starter.\n## if you want add this lib to an exists project\n1. install the typeorm and express and this package\n```\nnpm i express  @types/express --save\nnpm i typeorm sqlite reflect-metadata --save\nnpm i typeorm-json-api\n```\n\n2. add your typeorm configuration \n```typescript\n export const ormConfig = {\n  \"type\": \"sqlite\",\n  \"database\": \"db.sqlite\",\n  \"entities\": [\n    \"src/entities/*.ts\"\n  ],\n  \"logging\": false,\n  \"synchronize\": true\n}\n```\n\n3. add an entity to /src/entities, e.g. user.ts\n``` typescript\nimport {Entity, Column, PrimaryGeneratedColumn} from \"typeorm\";\n@Entity()\nexport class User {\n    @PrimaryGeneratedColumn()\n    id: number;\n    @Column()\n    firstName: string;\n    @Column()\n    lastName: string;\n}\n```\n\n### add router\n\n``` typescript\nimport {createCRUDRouter} from 'typeorm-json-api'\nconst app = express()\n...\napp.use('/api/repos', createCRUDRouter(ormConfig))\n```\n\n# log\nthe second parameter of createCRUDRouter is a callback function to log CRUD request\n## default log\n```typescript\ncreateCRUDRouter(ormConfig)\nor\ncreateCRUDRouter(ormConfig, undefined)\n```\n## disable log\n```typescript\ncreateCRUDRouter(ormConfig,null)\n```\n## customze log\n```typescript\ncreateCRUDRouter(ormConfig,(level,msg)=\u003e{\n  /* your own log code*/ \n  })\n```\n# authorization\nthe third parameter of createCRUDRouter is the verifyToken handler,\n``` typescript\napp.use('/api/repos', createCRUDRouter(ormConfig, undefined,verifyToken))\n```\nthe following is a very simple version of verify token handler\n``` typescript\nconst secret = 'very secret'\nfunction getToken(req: Request, res: Response) {\n    const token = jwt.sign({ username: 'joe@a.com' }, secret, { expiresIn: '1800s' })\n    res.send(token)\n}\nfunction verifyToken(req, res, next) {\n    console.log('in verify token')\n    const authHeader = req.headers['authorization']\n    const token = authHeader \u0026\u0026 authHeader.split(' ')[1]\n    if (token == null) {\n        return res.sendStatus(401)\n    }\n    jwt.verify(token, secret, (err: any, user: any) =\u003e {\n        if (err) {\n            return res.sendStatus(403)\n        }\n        req.user = user\n        next() // pass the execution off to whatever request the client intended\n    })\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformcms%2Ftypeorm-json-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformcms%2Ftypeorm-json-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformcms%2Ftypeorm-json-api/lists"}