Test-Driving API Endpoints
SvelteKit makes creating API endpoints a breeze. This chapter looks at how you can use tests to drive and prove your API endpoints.
In the preceding chapter, you saw how we could push business logic out of SvelteKit and into plain JavaScript. We can make use of the extracted birthdayRepository
object in the new API endpoints. We will now add endpoints for creating, updating, and getting birthdays using the addNew
, replace
, and getAll
functions from the repository.
Figure 10.1 shows how our system design is shaping up. The endpoints we’ll create in this chapter are very lightweight, thanks to the fully specified birthdayRepository
object:
Figure 10.1 – SvelteKit components flowing into the inner system
We will cover the following key topics in this chapter:
- Creating a service test with Playwright
- Adding an API endpoint for retrieving data
- Adding an API endpoint for saving data
- Adding an...