4.3 KiB
4.3 KiB
Exo 3.2 "API CRUD" - BOICHÉ Gauvain
Commandes
POST /api/equipements
Côté client
> curl -i -X POST http://127.0.0.1:5000/api/equipments -H "Content-Type: application/json" -d '{"hostname": "test-web-35"}'
HTTP/1.1 201 CREATED
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:48:45 GMT
Content-Type: application/json
Content-Length: 72
Connection: close
{
"actif": true,
"hostname": "test-web-35",
"id": 3,
"ip": ""
}
> curl -i -X POST http://127.0.0.1:5000/api/equipments -H "Content-Type: application/json" -d '{"hostname": "test-web-37", "ip": "192.168.250.69"}'
HTTP/1.1 201 CREATED
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:49:10 GMT
Content-Type: application/json
Content-Length: 86
Connection: close
{
"actif": true,
"hostname": "test-web-37",
"id": 4,
"ip": "192.168.250.69"
}
> curl -i -X POST http://127.0.0.1:5000/api/equipments -H "Content-Type: application/json" -d '{"ip": "192.168.250.67"}'
HTTP/1.1 400 BAD REQUEST
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:49:20 GMT
Content-Type: application/json
Content-Length: 46
Connection: close
{
"erreur": "Le hostname est obligatoire"
}
Côté serveur
127.0.0.1 - - [07/Jul/2026 11:48:45] "POST /api/equipments HTTP/1.1" 201 -
127.0.0.1 - - [07/Jul/2026 11:49:10] "POST /api/equipments HTTP/1.1" 201 -
127.0.0.1 - - [07/Jul/2026 11:49:20] "POST /api/equipments HTTP/1.1" 400 -
PUT /api/equipements/<id>
Côté client
> curl -i http://127.0.0.1:5000/api/equipments
HTTP/1.1 200 OK
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:50:19 GMT
Content-Type: application/json
Content-Length: 452
Connection: close
{
"equipments": [
{
"active": true,
"hostname": "srv-web-01",
"id": 1,
"ip": "192.168.1.10"
},
{
"active": true,
"hostname": "sw-access-02",
"id": 2,
"ip": "192.168.1.2"
},
{
"actif": true,
"hostname": "test-web-35",
"id": 3,
"ip": ""
},
{
"actif": true,
"hostname": "test-web-37",
"id": 4,
"ip": "192.168.250.69"
}
]
}
> curl -i -X PUT http://127.0.0.1:5000/api/equipments/4 -H "Content-Type: application/json" -d '{"ip": "192.168.4.20"}'
HTTP/1.1 200 OK
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:50:56 GMT
Content-Type: application/json
Content-Length: 84
Connection: close
{
"actif": true,
"hostname": "test-web-37",
"id": 4,
"ip": "192.168.4.20"
}
> curl -i -X PUT http://127.0.0.1:5000/api/equipments/5 -H "Content-Type: application/json" -d '{"ip": "192.168.39.45"}'
HTTP/1.1 404 NOT FOUND
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:51:08 GMT
Content-Type: application/json
Content-Length: 50
Connection: close
{
"erreur": "\u00c9quipement non trouv\u00e9"
}
Côté serveur
127.0.0.1 - - [07/Jul/2026 11:50:19] "GET /api/equipments HTTP/1.1" 200 -
127.0.0.1 - - [07/Jul/2026 11:50:56] "PUT /api/equipments/4 HTTP/1.1" 200 -
127.0.0.1 - - [07/Jul/2026 11:51:08] "PUT /api/equipments/5 HTTP/1.1" 404 -
DELETE /api/equipements/<id>
Côté client
> curl -i -X DELETE http://127.0.0.1:5000/api/equipments/5
HTTP/1.1 404 NOT FOUND
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:52:51 GMT
Content-Type: application/json
Content-Length: 50
Connection: close
{
"erreur": "\u00c9quipement non trouv\u00e9"
}
> curl -i -X DELETE http://127.0.0.1:5000/api/equipments/4
HTTP/1.1 200 OK
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:52:54 GMT
Content-Type: application/json
Content-Length: 66
Connection: close
{
"message": "\u00c9quipement supprim\u00e9 avec succ\u00e8s"
}
> curl -i -X DELETE http://127.0.0.1:5000/api/equipments/4
HTTP/1.1 404 NOT FOUND
Server: Werkzeug/3.1.8 Python/3.14.6
Date: Tue, 07 Jul 2026 09:52:57 GMT
Content-Type: application/json
Content-Length: 50
Connection: close
{
"erreur": "\u00c9quipement non trouv\u00e9"
}
Côté serveur
127.0.0.1 - - [07/Jul/2026 11:52:51] "DELETE /api/equipments/5 HTTP/1.1" 404 -
127.0.0.1 - - [07/Jul/2026 11:52:54] "DELETE /api/equipments/4 HTTP/1.1" 200 -
127.0.0.1 - - [07/Jul/2026 11:52:57] "DELETE /api/equipments/4 HTTP/1.1" 404 -