phearzero
04/18/2023, 1:04 AMopt
query param and use HTTP Methods.
- GET
returns the current state (get power|nodeinfo)
- PUT
updates the node state (set power, etc)
- POST
perform an operation, set bulk data, or upload data (network reset, firmware update)
Second is make the routes more deterministic by moving the type
query param into a path. Example:
bash
# BMC USB State
curl -X GET 127.0.0.1/api/bmc/usb
# Array response
curl -X GET 127.0.0.1/api/bmc/info
curl -X GET 127.0.0.1/api/bmc/power
# Single node response
curl -X GET 127.0.0.1/api/bmc/node/1/info
# Set Power using Array
curl -X POST -d '[1,1,0,0]' 127.0.0.1/api/bmc/power
# Individual control
curl -X PUT -d '1' 127.0.0.1/api/bmc/node/1/power
https://github.com/PhearZero/turing-pi-api/blob/main/v1.0.1.oas.ymldestomes
04/20/2023, 12:02 AM/api/bmc/1/info
etc. instead of passing query parameters. ( hah, totally missed the single node resource route you have )phearzero
04/20/2023, 2:56 PMbash
curl -X GET 127.0.0.1/api/bmc/node/1
Response:
json
{
info: "unkown",
power: 1,
usb: 0,
}
Patch:
bash
curl -X PATCH -d '{power: 0}' 127.0.0.1/api/bmc/node/1
This can go up the root to things like /api/bmc
and possibly hide some child data with a query like ?include_all=true
json
{
"usb": 0,
"other": {},
"node1": {
info: "unkown",
power: 1,
usb: 0,
},
"node2": {
info: "unkown",
power: 1,
usb: 0,
}
}
destomes
04/20/2023, 6:09 PMpetermcd
04/20/2023, 6:48 PMphearzero
04/20/2023, 7:09 PM_dhanos_
04/23/2023, 3:41 AMphearzero
04/23/2023, 4:15 AM