Loading...
Loading...
REST API design with HTTP methods and status codes. Use for web APIs.
npx skill4agent add g1joshi/agent-skills rest-api// Express.js Example
app.get("/users/:id", async (req, res) => {
const user = await db.find(req.params.id);
if (!user) return res.status(404).json({ error: "Not Found" });
// HATEOAS (Hypermedia As The Engine Of Application State) - optional but "True REST"
res.json({
...user,
links: {
self: `/users/${user.id}`,
orders: `/users/${user.id}/orders`,
},
});
});/users/123GET /ordersPOST /ordersPATCH /orders/1DELETE /orders/1?sort=-created_at&limit=10&page=2&status=active/v1/usersAccept: application/vnd.myapi.v1+jsonuser_id{ "error": "failed" }| Error | Cause | Solution |
|---|---|---|
| Sending POST to a GET-only endpoint. | Check HTTP verb. |
| Sending XML when JSON expected. | Set |
| Browser blocking cross-origin request. | Set |