DevConnectDevConnect
Sign up · Log in
← back to the feed
0
showcase

Shipped: Bookmark service

What Was Built A bookmark service API with validation at the boundary — rejecting bad input before it reaches business logic. Quick Demo npm install && npm start # Create curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{"url":"https://github.com","title":"GitHub"}' # Duplicate (returns 200, not 201) curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{"url":"https://github.com","title":"Diff"}' # List (shows 1 row) curl localhost:3000/bookmarks # Bad input (returns 400 with field name) curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{"url":"not-url"}' Acceptance Criteria Verification 1. Three or more endpoints, each returning a documented status code The service has four endpoints: - POST /bookmarks → returns 201 (created), 200 (duplicate), or 400 (validation error) - GET /bookmarks → returns 200 with array of bookmarks - GET /bookmarks/:id → returns 200, 400 (bad ID), or 404 (not found) - DELETE /bookmarks/:id → returns 204, 400, or 404 2. Malformed input returns 400 with a message naming the field Test it: curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{}' Response: {"error":"validation_failed","fields":{"url":"required"}} The error names the field (url) and the rule (required). 3. No input produces a 500 Every validation path returns 400: - Empty body → 400 - Wrong type (number instead of string) → 400 - Missing url → 400 - Invalid url → 400 - Unknown fields → 400 - Long strings exceeding limits → 400 4. The same create request sent twice leaves one row Test it: # First request - creates row curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{"url":"https://github.com"}' # Second request - returns existing, no new row curl -X POST localhost:3000/bookmarks -H "Content-Type: application/json" -d '{"url":"https://github.com"}' # List shows only one row curl localhost:3000/bookmarks 5. README explains how repeats are recognized The README has a "Duplicate Detection" section explaining: - URL is used as unique identifier - Database has a UNIQUE constraint on URL - Same URL returns existing bookmark with 200, not a new row - Reasoning: two bookmarks with same URL are the same resource Repository: https://github.com/techtuber9988/bookmark-service Built for the Verified Backend Internship · an API that survives bad input
Add a comment
0/2000