API implementation - jpehkone21/PWP GitHub Wiki
๐ Chapter summary
In this section you must implement a RESTful API. The minimum requirements are summarized in the Minimum Requirements section of the Project Work Assignment. If you do not meet the minimum requirements this section WILL NOT be evaluated.- Implement a RESTful API
- Write tests for the API
โ๏ธ Chapter evaluation (max 21 points)
You can get a maximum of 21 points after completing this section. More detailed evaluation is provided in the evaluation sheet in Lovelace.๐ Content that must be included in the section
A list of all resourcess. Each resource should include its URL, a short description and supported methods. You should mark also which is the name of the class implementing the resource (if you have implemented such resource) Consider that you do not need to implement every resource you initially planned. The minimum requirements are summarized in the Minimum requirements section from the Project work assignment.โ๏ธ List your resources here. You can use the table below for listing resources. You can also list unimplemented resources if you think they are worth mentioning
| Resource name | Resource url | Resource description | Supported Methods | Implemented |
|---|---|---|---|---|
| Creatures | api/creatures/ | Lists all creatures | GET, POST | Implemented in CreatureCollection |
| Creature | api/creatures/<creature>
|
Access a specific creature | GET, PUT, DELETE | Implemented in CreatureItem |
| Humans | api/humans/ | Lists all humans | GET, POST | Implemented in HumanCollection |
| Human | api/humans/<human>
|
Access a specific human | GET, PUT, DELETE | Implemented in HumanItem |
| Animals | api/animals/ | Lists all animals | GET, POST | Implemented in AnimalCollection |
| Animal | api/animals/<animal>
|
Access a specific animal | GET, PUT, DELETE | Implemented in AnimalItem |
| Quotes | api/creatures/<creature>/quotes/ OR api/humans/<human>/quotes/ OR api/animals/<animal>/quotes/ |
Lists all quotes for a specific character | GET, POST | Implemented in QuotesCollection |
| Quote | api/creatures/<creature>/quotes/<quote_id> OR api/humans/<human>/quotes/<quote_id> OR api/animals/<animal>/quotes/<quote_id>
|
Access a specific quote | GET, PUT, DELETE | Implemented in QuoteItem |
๐ป TODO: SOFTWARE TO DELIVER IN THIS SECTION
The code repository must contain:- The source code for the RESTful API
- The external libraries that you have used
- We recommend to include a set of scripts to setup and run your server
- A database file or the necessary files and scripts to automatically populate your database.
- A README.md file containing:
- Dependencies (external libraries)
- How to setup the framework.
- How to populate and setup the database.
- How to setup (e.g. modifying any configuration files) and run your RESTful API.
- The URL to access your API (usually nameofapplication/api/version/)=> the path to your application.
NOTE: Your code MUST be clearly documented. For each public method/function you must provide: a short description of the method, input parameters, output parameters, exceptions (when the application can fail and how to handle such fail). In addition should be clear which is the code you have implemented yourself and which is the code that you have borrowed from other sources. Always provide a link to the original source. This includes links to the course material.
โ๏ธ You do not need to write anything in this section, just complete the implementation.
๐ป TODO: SOFTWARE TO DELIVER IN THIS SECTION
The code repository must contain:- The code to test your RESTful API (Functional test)
- The code of the test MUST be commented indicating what you are going to test in each test case.
- The test must include values that force error messages
- The external libraries that you have used
- We recommend to include a set of scripts to execute your tests.
- A database file or the necessary files and scripts to automatically populate your database.
- A README.md file containing:
- Dependencies (external libraries)
- Instructions on how to run the different tests for your application.
Remember that you MUST implement a functional testing suite. A detailed description of the input / output in the a REST client plugin.
In this section it is your responsibility that your API handles requests correctly. All of the supported methods for each resource should work. You also need to show that invalid requests are properly handled, and that the response codes are correct in each situation.
โ๏ธ Most important part of this section is completing the implementation. Write down here a short reflection on which are the main errors you have solved thanks to the functional tests.
Writing the tests really helped to spot some small errors in the implementation. Some of these included incorrect response codes, typos in the urls and copypaste errors. When testing manually, we usually only tested adding quotes to one type of character (e.g. creature). With tests, we were able to spot more errors in the human and animal resources that we wouldn't have otherwise noticed.
Below is the test coverage.

๐ Content that must be included in the section
Explain briefly how your API meets REST principles. Focus specially in these three principles: Addressability, Uniform interface, Statelessness. Provide examples (e.g. how does each HTTP method work in your API). Note that Connectedness will be addressed in more depth in Deadline 4.โ๏ธ Write your text here
Addressability: Each resource is uniquely identifiable, because they all have unique urls. Creatures, humans and animals are identifiable by their names, and quotes with their id.
Uniform interface: The API implements standart http methods for each resource. For collections GET and POST are implemented, and for individual items GET, PUT and DELETE are implemented.
Stateleness: The application doesn't store any session spesific data, and processes every request independetly. The request will contain all necessary data that is needed to process it.
๐ Details on extra features
This section lists the additional features that will be graded as part of the API but are not required. In addition to implementing the feature you are also asked to write a short description for each.๐ Fill this section if you used URL converters
Write a short rationale of how URL converters are used, including your thoughts on the possible trade-offs. Go through all URL parameters in your API and describe whether they use a converter, what property is used for converting, or why it's not using a converter.โ๏ธ Write your text here
We implemented converters for all of our resources. They are implemented in the utils.py file.
The URL parameters in our API are
-
<creature>(specific creature's name) -
<human>(specific human's name) -
<animal>(specific animal's name) -
<quote>(specific quote's id)
Converters in our API work well, because otherwise we would need to convert the URL parameters anyway in most of our methods. All of our resources are also uniquely identifiable, so that also supports us using converters for all resources. Using converters will add overhead to our application, but we don't think it's too much, considering we don't have very long URLs.
๐ Fill this section if you used JSON schema validation
Write a short description of your JSON schemas, including key decision making for choosing how to validate each field.โ๏ธ Write your text here
We implemented schema validation for all of our resources. We didn't choose to make any major restrictions for the properties at this point. We only defined the allowed data types and required fields. Later we might add some restrictions, for example creature's types or animal's species.
Creature:
- Only Name is required
- Age must be number
- Picture, type, special_force must be strings
- Additional fields are not allowed
Human:
- Only name is required
- Age must be number
- Picture, relation, hobby must be strings
- Additional fields are not allowed
Animal:
- Only name is required
- Age must be number
- Picture, species, environment must be strings
- Additional fields are not allowed
Quote:
- Quote and mood are required
- Mood must be number
- Quote must be string
๐ Fill this section if you implemented server side caching
Explain your caching decisions here. Include an explanation for every GET method in your API, explaining what is cached (or why it is not cached), and how long is it cached (and why). If you are using manual cache clearing, also explain when it happens.โ๏ธ Write your text here
๐ Fill this section if you implemented authentication
Explain your authentication scheme here. Describe the authentication requirements for each resource in your API, and your reasoning for the decisions. In addition, provide a plan for how API keys will be distributed, even if the distribution is not currently implemented.โ๏ธ Write your text here
๐ If you have use AI during this deliverable, explain what tool/s you have used and how. In the tests, the client() function is made with ChatGPT (marked in the code). Also ChatGPT was used to understand some error messages and give some suggestions how to fix them. In those cases, no code was directly copied, but some suggestions weren used and modified to fit our implementation.
| Task | Student | Estimated time |
|---|---|---|
| API implementation | Johanna Pehkonen | 8h |
| API implementation | Iina Nikkarikoski | 8h |
| API implementation | Iiris Kivelรค | 8h |