Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 1.83 KB

prefer-collections-with-pagination.md

File metadata and controls

57 lines (43 loc) · 1.83 KB

Prefer API collections with pagination (@ecocode/prefer-collections-with-pagination)

⚠️ This rule warns in the ✅ recommended config.

Why is this an issue?

Pagination helps in optimizing the performance of API requests, especially when dealing with large datasets. Instead of retrieving the entire dataset in a single request, pagination allows fetching a smaller subset of data, reducing the response time and resource usage.

Fetching only the necessary data reduces the amount of data transmitted over the network. This is particularly important for users on limited bandwidth or mobile devices. Pagination ensures that only the relevant data is transferred, conserving bandwidth and improving overall network efficiency.

This rule is built for the NestJS framework but can work with a controller @Controller() and a decorated method @Get().

@Controller()
class Test {
  @Get()
  public find(): Promise<string[]> {
  } // Non-compliant
}
interface Pagination {
  items: string[];
  currentPage: number;
  totalPages: number;
}

@Controller()
class Test {
  @Get()
  public find(): Promise<Pagination> {
  } // Compliant
}

Resources

Documentation

Articles & blog posts