A sample RESTful API built Nest
The API has only one endpoint GET /api/users/{userId}
to fetch user details. MongoDB is used as the database, with typegoose as the ORM.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
The API documentation is available at http://localhost:3000/docs when the app is running locally. The documentation is a Swagger, which is auto generated by the NestJS Swagger module.
The API is rate limited using the nestjs-throttler module. The rate limit is set to 10 requests per minute.
The API uses the NestJS Exception Filters to handle errors. The API returns a JSON response with the following structure for all errors:
{
"statusCode": 400,
"message": "Bad Request",
"error": "Bad Request"
}
Update src/filters/http-exception.filter.ts file, line 34
to send errors to external services like Slack or Sentry.
The API uses the custom logger midilleware to log all requests to console. The log file is located at src/logger.ts
.