0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ページネーションのクエリパラメータについて考える

0
Posted at

はじめに

APIの設計をする際、クエリパラメータを何気なく決めていた。
ぱっと理解できるAPIを設計する為、ページネーションを実現する方法を軽く調べたのでメモとして残す。

必要なクエリパラメータ

ページネーション(pagination)を実現する為、取得数取得位置のクエリパラメータが必要となる。
世の中に公開されているAPI毎にこの値はまちまちだが、推奨される形式も存在する。

per_page, pageパターン

  • ページ単位で指定する
  • pageは1からstart
  • per_page=50&page=3のように指定

limit, offsetパターン

  • アイテム数単位で指定
  • offsetは0からstart
  • 1limit=50&offset=10`のように指定

どちらを使うべき

結論どちらでもOK。ただし、limit, offsetパターンの方が自由度は高い(n番目から100アイテムなど柔軟に指定可能)
ただしこの2パターンのみでは相対位置を利用する形となるので、更新等も考慮すると絶対位置を表す値も必要となる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?