COMP9321Assignments 辅导讲解、辅导java json、辅导java REST API 辅导留学生web service
调试
Resources / Assignments (/COMP9321/18s2/resources/20310) / Week 6 (/COMP9321/18s2/resources/20312)
/ Assignment Description
Assignment Description
Data Service for World Bank Economic Indicators
In this assignment, you are asked to develop a Flask-Restplus data service that allows a client to read and store some publicly available
economic indicator data for countries around the world, and allow the consumers to access the data through a REST API.
IMPORTANT : For this assignment , you will be asked to access the given Web content programmatically. Some Web hosts do not allow
their web pages to be accessed programmatically, some hosts may block your IP if you access their pages too many times. During the
implementation, download a few test pages and access the content locally - try not to perform too many programmatically.
The source URL: http://api.worldbank.org/v2/ (http://api.worldbank.org/v2/)
(http://api.worldbank.org/v2/) Documentations on API Call Structure:
(https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-api-basic-call-structure)
https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-api-basic-call-structure
(https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-api-basic-call-structure)
(https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-api-basic-call-structure)
The World Bank indicators API provides 50 year of data over more than 1500 indicators for countries around the world.
List of indicators can be found at: http://api.w o rldbank.org/v2/indicators (http://api.worldbank.org/v2/indicators)
List of countries can be found at: (http://api.worldbank.org/v2/countries) http://api.worldbank.org/v2/countries
(http://api.worldbank.org/v2/countries)
As the documentation shows , you can construct URLs specifying different parameters to acquire necessary data. Use a custom URL
to get information about a specific indicator. For example, the data on the GDP of all countries from 2012 to 2017 can be acquired via
this URL: (http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2012:2017) http://api.worldbank.org
/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2012:2017&format=json (http://api.worldbank.org/v2/countries/all/indicators
/NY.GDP.MKTP.CD?date=2012:2017&format=json)
For this assignment we are interested in annual values of a user specified indicator from 2012 to 2017 for one or all countries. The
content of the file is quite straightforward. The data service specification will ask you to 'import' this data into a 'data storage'. You
should inspect the content of the file carefully and decide on a data model and storage method. You will find that a JSON format is
suitable to accessing data and publishing it.
You should use mLab : MongoDB as a service ( https://mlab.com/ (https://mlab.com/) ) for your data storage. This way
examiners can run your implementation to access your data stored remotely.
Assignment Specification
Specification Make Submission Check Submission Collect Submission
Assignment Description | COMP9321 18s2 | WebCMS3 https://webcms3.cse.unsw.edu.au/COMP9321/18s2/resources/20832
1 of 11 18/9/18, 09:33
The data service should use JSON format to publish its data and implement following operations.
1- Import a collection from the data service
This operation can be considered as an on-demand 'import' operation. The service will download the JSON data for all countries
(http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2012:2017&format=json) respective to the year 2012 to
2017 and identified by the indicator id given by the user and process the content into an internal data format and store it in the
database ( mLab ).
Parameters should be given to the endpoint (in the payload) by the user:
indicator_id : an indicator (http://api.worldbank.org/v2/indicators) http://api.worldbank.org/v2/indicators
(http://api.worldbank.org/v2/indicators)
After importing the collection, the service should return a response containing at least the following information:
location : the URL with which the imported collection can be retrieved
collection_id : a unique identifier automatically generated
creation_time : the time the collection stored in the database
Example:
HTTP operation: POST /
Input Payload:
{ "indicator_id" : "NY.GDP.MKTP.CD" }
Returns: 201 Created
{
"location" : "//",
"collection_id" : "",
"creation_time": "2018-04-08T12:06:11Z",
"indicator" : ""
}
The return response contains the location of the data entry created as the result of the processing the import. What is shown
above is just a suggestion. You can decide what else is appropriate. You do not have to return the actual imported content with
POST. Just return the location.
You should return appropriate responses in case of invalid indicators or any invalid attempts to use the endpoint ( e.g. If the input
indicator id doesn't exist in the data source, return error 400)
If an input contains a n indicator that already has been imported before, you should still return the location of the data entry - but
with status code 200 OK (instead of 20 1 Created).
A POINT TO PONDER ABOUT: An `asynchronous POST'?? If a POST takes too long, you may not want the client to wait. What
you would do? You do not need to address this in the assignment.
The source API has pagination; in order to get all of data you need to send many request to import a single collection; however,
you are required to get only first two pages instead of all:
http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2012:2017&format=json&page=2
(http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2012:2017&format=json&page=2)
The data entries inside the collection must be converted as described below:
Data entry conversion:
Assignment Description | COMP9321 18s2 | WebCMS3 https://webcms3.cse.unsw.edu.au/COMP9321/18s2/resources/20832
2 of 11 18/9/18, 09:33
Here is an example of source data entry as it is in the source API (http://api.worldbank.org/v2/countries/all/indicators
/NY.GDP.MKTP.CD?date=2012:2017&format=json) :
{
"indicator": {
"id": "NY.GDP.MKTP.CD",
"value": "GDP (current US$)"
},
"country": {
"id": "1A",
"value": "Arab World"
},
"countryiso3code": "",
"date": "2016",
"value": 2500164034395.78,
"unit": "",
"obs_status": "",
"decimal": 0
}
However, you do not need to store all of its attributes; instead convert it to a JSON format as below:
{
"country": "Arab World",
"date": "2016",
"value": 2500164034395.78
}
And as a result a collection should be formatted and stored in the database (mLab) as follow:
{
"collection_id" : "",
"indicator": "NY.GDP.MKTP.CD",
"indicator_value": "GDP (current US$)",
"creation_time" : ""
"entries" : [
{ "country": "Arab World", "date": "2016", "value": 2500164034395.78 },
{ "country": "Australia", "date": "2013", "value": 780016444034.00 },
...
]
}
2- Deleting a collection with the data service
This operation deletes an existing collection from the database. The interface should look like as below:
HTTP operation: DELETE //{collection_id}
Returns: 200 OK
Assignment Description | COMP9321 18s2 | WebCMS3 https://webcms3.cse.unsw.edu.au/COMP9321/18s2/resources/20832
3 of 11 18/9/18, 09:33
{
"message" :"Collection = is removed from the database!"
}
3 - Retrieve the list of available collections
This operation retrieves all available collections. The interface should look like as like below:
HTTP operation: GET /
Returns: 200 OK
[
{
"location" : "//",
"collection_id" : "collection_id_1",
"creation_time": "