ephrimlawrence / demo-users-api

An API built with NestJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Users API

A sample RESTful API built Nest

Description

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.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

API Documentation

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.

Rate Limiting

The API is rate limited using the nestjs-throttler module. The rate limit is set to 10 requests per minute.

Error Handling

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.

Logging

The API uses the custom logger midilleware to log all requests to console. The log file is located at src/logger.ts.

About

An API built with NestJS


Languages

Language:TypeScript 95.4%Language:JavaScript 4.6%