Skip to content
Snippets Groups Projects
Commit 76e4d94d authored by Nihad Abbasov's avatar Nihad Abbasov
Browse files

add pagination to API

parent 6817a6a2
No related branches found
No related tags found
1 merge request!1360API pagination
Loading
Loading
@@ -23,6 +23,13 @@ GET http://example.com/api/v2/projects?private_token=QVy1PB7sTxfy4pqfZM1U
 
The API uses JSON to serialize data. You don't need to specify `.json` at the end of API URL.
 
#### Pagination
When listing resources you can pass the following parameters:
+ `page` (default: `1`) - page number
+ `per_page` (default: `20`, max: `100`) - how many items to list per page
## Contents
 
+ [Users](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/users.md)
Loading
Loading
Loading
Loading
@@ -14,6 +14,10 @@ module Gitlab
@project
end
 
def paginate(object)
object.page(params[:page]).per(params[:per_page].to_i)
end
def authenticate!
error!({'message' => '401 Unauthorized'}, 401) unless current_user
end
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# GET /issues
get do
present current_user.issues, with: Entities::Issue
present paginate(current_user.issues), with: Entities::Issue
end
end
 
Loading
Loading
@@ -21,7 +21,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/issues
get ":id/issues" do
present user_project.issues, with: Entities::Issue
present paginate(user_project.issues), with: Entities::Issue
end
 
# Get a single project issue
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/milestones
get ":id/milestones" do
present user_project.milestones, with: Entities::Milestone
present paginate(user_project.milestones), with: Entities::Milestone
end
 
# Get a single project milestone
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# GET /projects
get do
@projects = current_user.projects
@projects = paginate current_user.projects
present @projects, with: Entities::Project
end
 
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# GET /users
get do
@users = User.all
@users = paginate User
present @users, with: Entities::User
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment