this project is a implementation demo which meets the requirement described in REQUIREMENT.md
.
this is a node.js RESTful api server built by koa + typescript + prisma.
it contains:
- a set of
CRUD
method for single entity: user - an api to query multiple users.
- a
login
api to get the jwt token.
we support 6 apis at this project. five for entity CRUD and one for login(to get jwt token)
- method:
POST
- url: /login
- params:
loginRequest {
name String required // any string will be ok
}
- method:
GET
- url: /users
- params:
?name=xxx&mail=xxx
- method:
GET
- url: /users/:userId
- params: none
- method:
POST
- url: /users
- params:
createRequest {
name String required
email String required // should be valid email format.
password String required
}
- method:
PUT
- url: /users
- params:
updateRequest {
id String required
name String optional
email String optional
password String optional
}
- method:
DEL
- url: /users/:userId
- params: none
run pnpm i
or yarn
to install the node_modules of this project.
we put important data in .env
file which is stored locally and will not be uploaded to git.
the .env file is not provided in this public repository.
after receiving the .env
content, create a .env
file and paste the content into it, and put it at the root of project like below:
we use prisma as the ORM lib in this project. before running your server, you should generate the prismaClient
and initialize the db(optional)
.
by generating prismaClient, run:
pnpm prisma generate
!IMPORTANT: every time you changed the
prisma.scheme
, you should regenerate the prismaClient.
by initializing the db, run:
pnpm prisma migrate --name init
!IMPORTANT: since we have already migrated the verceldb to sync with our prisma scheme, this step can be skipped.
we use a vercel PostgreSQL in this project. the verceldb is free but limited, so there may be updates if we run out of the resource in verceldb.
Updating will be made by change the .env
file content.
after doing the above procedures, you can launch the server by running:
pnpm dev
or
yarn dev
also you can build it by pnpm built
and serve it by running
node dist/index.js
or
pnpm serve
I use Postman
to test api.
in resource
folder there is a postman config which is exported by me. you can import this config into postman to test the 6
apis supported by this server.