Codele / How software is built
Build a small API
Last time an app asked a service for data. Now you stand on the other side: a tiny to-do service that receives requests, picks a route, changes its list and replies.
- A route is a method plus a path, such as GET /todos. The service checks routes from the top and uses the first match.
- GET reads, POST adds, DELETE removes. The method says what to do.
- A status number tells the app how it went: 200 OK, 201 Created, 404 Not found.
- Always answer plainly when something is missing. A 404 is better than pretending it worked.
- Real services use a counter for new ids, so a removed id is never reused. Here the new id is the list length plus one, to keep the code short.
Loading the playable lesson…