- types
- endpoints
- composables
- tests
- create types for the endpoints/data shapes
- create server API endpoints in
server/api/*.ts
, and include the request method in the filename (example.get.ts
,example.post.ts
) - get route information from the
(event)
object -event.context.params
- make the data fetching functions in
composables/*.ts
- include error handling
- use caching (sessionStorage) to cache the requested data on the client (so if user's navigate between already visited URLs the data is loaded from their browser cache instead of being requested again from our API). Can put this "cached fetch" in its own compsoable.
- validate the data in your server routes
- only fetch the necessary data needed to hydrate the page (
pick
, etc.) - use drizzle-zod for API input validation
Types of API tests:
- Unit tests / Endpoint tests - to call & test individual endpoints w/ various inputs and verify the expected results. Make sure to test both positive & negative scenarios.
- Integration tests - test certain workflows (aka multiple steps).
- Contract tests - to verify the API is in-line with the provider contract. Data points haven't changed, data types haven't changed, data shape hasn't changed, etc.
- Security tests
- Performance tests
- Data-driven tests (test parameterization).
Unit tests:
- test that endpoints work (status code)
- test the endpoint only works with the intended request type
- test the response data shape is as expected (
.jsonSchema
) - the response contains the expected data
- the header information contains expected data
- response time & size
- only returns what it needs (not extra/unused information)
- there is a max on the amount of data able to be requested
Integration tests & more:
- use postman to create 'collections' for the endpoints and then auto generate tests for them (right click on collection > generate tests).
Contract tests:
- Create a 'collection' of tests in postman that test all the API's configurations - run the tests on any/every update/change to the API.
- Have the contract documented (API Specification file)
- Use postman to auto generate contract tests (postman -> searchbar -> 'generate contract tests')
Tip: utilize postman interceptor to save all requests to the API and from there genereate the API specification (if you didn't start with the schema).. then create your tests to do the asserts/verifications.
API Monitors:
- setup API monitoring to run against the production API and alert results
Test CI & reporting:
- Run in CI pipeline / builds
- Include performance tests in CI
Performance testing:
- Processing load (response time, response size)
- Memory load
- Connection load
- Spike load
- Ramp load
- Endurance load