WIP: Pagination implemented #5

Closed
danny-mhlv wants to merge 0 commits from refs/pull/5/head into develop
danny-mhlv commented 2022-08-09 17:00:23 +00:00 (Migrated from 85.143.176.51:3000)

Examples of API calls

Response structure

Structure of the API response is presented below. In general API response for both endpoints - is a page, which contains documents acquired through querying Elasticsearch and metadata, which provides additional information about current page.

  • Note: the API response structure is the same for both described endpoints.
{
	"data": [
        {...},
        {...},
        {...}
	],
	"meta": {
		"total": 3,
		"pagenum": 1,
		"order": "DESC",
		"hasNext": false,
		"hasPrev": false,
		"pagesize": 10
	}
}

Property 'data' holds an array of documents, returned from the Elasticsearch.

Property 'meta' holds an object of metadata for the page.

/papers/{uuid}

This example demonstrates the case of addressing the /papers/{uuid} endpoint.

Request

http://localhost:8085/papers/eeeb2d01-8315-454e-b33f-3d6caa25db42

Response

{
	"data": [
		{
			"_index": "papers",
			"_id": "1012",
			"_score": 3.5457783,
			"_source": {
				"id": "491c559d-1d33-4f23-86c6-2c0f177d4add",
				"title": "H. R. Jothipala",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Physics",
				"summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a"
			}
		}
	],
	"meta": {
		"total": 1,
		"pagenum": 1,
		"order": "DESC",
		"hasNext": false,
		"hasPrev": false,
		"pagesize": 10
	}
}

As you can see - when /papers/{uuid} endpoint is accessed - the result is a page, containing only 1 element and metadata.

/papers/search?

List of query parameters:

  • query (Mandatory, string)

  • page (Optional, number)

  • limit (Optional, number)

  • order (Optional, string, "asc"/"desc")

Example, provided below demonstrates the case of addressing the /papers/search? endpoint.

Request

http://localhost:8085/papers/search?query=a&page=1&limit=3&order=desc

Response

{
	"data": [
		{
			"_index": "papers",
			"_id": "27",
			"_score": 0.52969605,
			"_source": {
				"id": "491c559d-1d33-4f23-86c6-2c0f177d4add",
				"title": "H. R. Jothipala",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Physics",
				"summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a"
			}
		},
		{
			"_index": "papers",
			"_id": "20",
			"_score": 0.5266665,
			"_source": {
				"id": "2766f61d-39c0-4f77-925f-e7766bee280a",
				"title": "Complex number",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Mathematics",
				"summary": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every complex number can be expressed in the form a + bi, where a and b are real numbers",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every "
			}
		},
		{
			"_index": "papers",
			"_id": "13",
			"_score": 0.5177823,
			"_source": {
				"id": "1e9c4e94-bc14-43ed-afec-9d00ec82f2ce",
				"title": "Zenith Z-100",
				"authors": [
					"PaperGen",
					"Danny"
				],
				"topic": "Computing",
				"summary": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS)",
				"tags": [
					"Tag1",
					"Tag2",
					"Tag3"
				],
				"content": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS). It was a competitor to the IBM PC.\n\n\n== Design ==\nThe Zenith Data Systems Z-100 is a pre-assembled version of the Heathkit "
			}
		}
	],
	"meta": {
		"total": 37,
		"pagenum": "1",
		"order": "DESC",
		"hasNext": true,
		"hasPrev": false,
		"pagesize": "3"
	}
}

Here - the 'data' property holds 3 elements (limit per page is specified in the appropriate query parameter). This limit is also present in 'meta' property, as 'pagesize'.

# Examples of API calls ## Response structure Structure of the API response is presented below. In general API response for both endpoints - is a page, which contains **documents** acquired through querying Elasticsearch and **metadata**, which provides additional information about current page. * *Note: the API response structure is the same for both described endpoints.* ```json { "data": [ {...}, {...}, {...} ], "meta": { "total": 3, "pagenum": 1, "order": "DESC", "hasNext": false, "hasPrev": false, "pagesize": 10 } } ``` Property 'data' holds an array of documents, returned from the Elasticsearch. Property 'meta' holds an object of metadata for the page. ## /papers/{uuid} This example demonstrates the case of addressing the ***/papers/{uuid}*** endpoint. ***Request*** ```url http://localhost:8085/papers/eeeb2d01-8315-454e-b33f-3d6caa25db42 ``` ***Response*** ```json { "data": [ { "_index": "papers", "_id": "1012", "_score": 3.5457783, "_source": { "id": "491c559d-1d33-4f23-86c6-2c0f177d4add", "title": "H. R. Jothipala", "authors": [ "PaperGen", "Danny" ], "topic": "Physics", "summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a" } } ], "meta": { "total": 1, "pagenum": 1, "order": "DESC", "hasNext": false, "hasPrev": false, "pagesize": 10 } } ``` As you can see - when ***/papers/{uuid}*** endpoint is accessed - the result is a page, containing **only 1** element and metadata. ## /papers/search? List of query parameters: * query (Mandatory, string) * page (Optional, number) * limit (Optional, number) * order (Optional, string, "asc"/"desc") Example, provided below demonstrates the case of addressing the ***/papers/search?*** endpoint. ***Request*** ```url http://localhost:8085/papers/search?query=a&page=1&limit=3&order=desc ``` ***Response*** ```json { "data": [ { "_index": "papers", "_id": "27", "_score": 0.52969605, "_source": { "id": "491c559d-1d33-4f23-86c6-2c0f177d4add", "title": "H. R. Jothipala", "authors": [ "PaperGen", "Danny" ], "topic": "Physics", "summary": "Hettiarachchige Reginald Jothipala (Sinhala: එච්", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "Hettiarachchige Reginald Jothipala (Sinhala: එච්.ආර්. ජෝතිපාල; 12 February 1936 – 7 July 1987), popularly as H. R. Jothipala, was a Sri Lankan playback singer in the Sinhala cinema as well as a film a" } }, { "_index": "papers", "_id": "20", "_score": 0.5266665, "_source": { "id": "2766f61d-39c0-4f77-925f-e7766bee280a", "title": "Complex number", "authors": [ "PaperGen", "Danny" ], "topic": "Mathematics", "summary": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every complex number can be expressed in the form a + bi, where a and b are real numbers", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted i, called the imaginary unit and satisfying the equation i2 = −1; every " } }, { "_index": "papers", "_id": "13", "_score": 0.5177823, "_source": { "id": "1e9c4e94-bc14-43ed-afec-9d00ec82f2ce", "title": "Zenith Z-100", "authors": [ "PaperGen", "Danny" ], "topic": "Computing", "summary": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS)", "tags": [ "Tag1", "Tag2", "Tag3" ], "content": "The Z-100 computer is a personal computer made by Zenith Data Systems (ZDS). It was a competitor to the IBM PC.\n\n\n== Design ==\nThe Zenith Data Systems Z-100 is a pre-assembled version of the Heathkit " } } ], "meta": { "total": 37, "pagenum": "1", "order": "DESC", "hasNext": true, "hasPrev": false, "pagesize": "3" } } ``` Here - the 'data' property holds 3 elements (***limit*** per page is specified in the appropriate query parameter). This limit is also present in 'meta' property, as 'pagesize'.

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Scipaper/Backend#5
No description provided.