Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3rd: API Design #3

Open
1 of 12 tasks
misostack opened this issue Jul 29, 2022 · 2 comments
Open
1 of 12 tasks

3rd: API Design #3

misostack opened this issue Jul 29, 2022 · 2 comments

Comments

@misostack
Copy link
Owner

misostack commented Jul 29, 2022

Includes:

  • Controller and Methods for CRUD
  • Input validation: DTOs, Pipes
  • Unify response: input validation errors, crud responses, processing error, server error - Interceptors
  • API Doc with Swagger
  • Transform Output: class transformer and response DTOs
  • Pagination : limit, offset
  • Search: filter
  • Authorization: Middleware, Auth Guard, Role base Access Control
  • Unit Tests: Mock, Spy & Stubs
  • Upload file: multipart form data
  • Multi media endpoints: display image, download file, html, streaming
  • Cache: header cache keys, redis cache, cache invalidation
@misostack
Copy link
Owner Author

Controllers and methods for resource

Naming Controller: ExamplesController

Method Endpoint Params Method Description Success Status Response
GET /examples Query Param : ?filter={}&pageNumber=1&pageSize=10 index List examples Success: 200 Example[]
POST /examples Body : JSON data ExampleDTO create Create new example Success: 201 Example or exampleId
GET /examples/{id} Route Param: id show Get details of an example Success: 200 Example
PATCH /examples/{id} Route Param: id Body : JSON data ExampleUpdateDTO update Update an example partially Success: 200 exampleId
DELETE /examples/{id} Route Param : id remove Delete an example Success: 204 No content
@Controller('examples')
export class ExamplesController {
  constructor(private exampleService: ExampleService) {}
  // index, show, create, update, destroy
  @Get()
  index() {
    return [];
  }

  @Get(':id')
  show() {
    return {};
  }

  @Post('')
  create(@Body() payload): Example {
    const example: Example = this.exampleService.create(payload);
    return example;
  }

  @Patch(':id')
  update() {
    return {};
  }

  @Delete(':id')
  destroy() {
    return {};
  }
}

@misostack
Copy link
Owner Author

Validate Request Input in NestJS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant