Advanced level · Module 6: JavaScript Capstone Project · Lesson 2 of 5
Building the Visit API
Implement the Node.js API with validation, idempotent storage and summaries, with integration tests.
In this lesson you will
- Implement the sync and summary endpoints
- Test idempotency and validation
Key concepts
sync endpointupsert by IDsummary endpointintegration tests
The lesson
Implement POST /visits/sync to accept a batch of visits, validate each one and store them by ID, ignoring IDs already stored. Return which visits were accepted and which were rejected with reasons.
Implement GET /summary?area=… to return counts of visits per area and period.
Write integration tests that sync the same batch twice and check there are no duplicates, and that invalid visits are rejected without blocking valid ones.
Step by step
- Implement the sync endpoint with validation.
- Store visits by ID so duplicates are ignored.
- Implement the summary endpoint.
- Write integration tests for duplicates and invalid data.
Practice activity
Complete milestone 2: the tested visit API.
Expected result: All integration tests pass, including the double-sync test.
Check your understanding
-
How does the server avoid duplicate visits?
Show answer
It stores each visit by its ID and ignores IDs it already has.
-
Should one invalid visit block a whole batch?
Show answer
No; valid visits are accepted and invalid ones are reported individually.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.