Question: solve this in python. tnx | Task 4 . Definirajte aiohttp poslu itelj koji radi na portu 8 0 8 1 . Poslu itelj mora

solve this in python. tnx |Task 4. Definirajte aiohttp posluitelj koji radi na portu 8081. Posluitelj mora imati dvije rute: /proizvodi i /proizvodi/\{id\}. Prva ruta vraa listu proizvoda u JSON formatu, a druga rutu vraa tono jedan proizvod prema ID-u. Ako proizvod s traenim ID-em ne postoji, vratite odgovor s statusom 404 i porukom \{'error': 'Proizvod s traenim ID-em ne postoji'\}.
Proizvode pohranite u listu rjenika:
```
proizvodi =[
{"id": 1, "naziv": "Laptop", "cijena": 5000},
{"id": 2, "naziv": "Mis", "cijena": 100},
{"id": 3, "naziv": "Tipkovnica", "cijena": 200},
{"id": 4, "naziv": "Monitor", "cijena": 1000},
{"id": 5, "naziv": "slusalice", "cijena": 50}
J
```
within the main coroutine of the same script.
Test the server for all cases through a client session
Task 5. Upgrade the server from the previous task to also support the POST method on the /orders path.
This route receives JSON data about a new order in the following format. To begin, imagine that each order is simple and contains only one product and the quantity ordered:
```
{
"proizvod_id": 1,
"kolicina": 2
}
```
The handler coroutine of this method must check if the product with the requested ID exists within the products list .If it does not exist, return a response with status 404 and message \{'error': 'Product with requested ID does not
exist'\}. If the product exists, add a new order to the orders list and return a response with the completed orders list in JSON format and the appropriate status code.
Define the orders list globally, as an empty list.
Your final server must contain 3 routes: /products,/products/\{id\} and /orders .
Test the server for all cases through a client session within the main coroutine of the same script.
solve this in python. tnx | Task 4 . Definirajte

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!