~ 1 min read
How I approached a small TypeScript API
What I learned about making a small API easy to test, run, and hand off.
I built a small HTTP API in TypeScript and Express. It reminded me that getting an endpoint to return a response is only part of the work. I also want someone else to be able to run the project and check its behavior without having to ask how I set up my machine.
The project used Jest and Supertest. I like testing at the HTTP boundary because a function can return exactly the right value while the caller still gets the wrong status code. An HTTP test gives me a place to check what the caller actually sees. I also documented how to run the app with Docker Compose, so someone reading the project had a setup they could repeat.
If I did it again, I’d start with a little table of requests and expected responses. Even a few rows help decide what deserves an HTTP test and what can be tested with a plain function call. I’d also put the run, build, and test commands near the top of the README. The fewer details someone has to reconstruct, the easier it is to hand off even a small API.