API
114 bites tagged API — interview questions with model answers, and 60-second explainers.
res.send vs res.json vs res.end
Send is flexible and sets content type by type, json serializes and sets JSON content type, end is the raw http terminator with no body helpers. how Express sends responses. using res.end to return an object or claiming they.
How do you create a POST API endpoint in SvelteKit?
Add a +server.js file in a src/routes subdirectory, export a POST handler returning a Response, and note that +server files never run in the browser. Filesystem routing and server-only API routes in SvelteKit.
Runtime Response Validation with Schema Libraries
TypeScript types evaporate at runtime, so a fetch response typed as User[] can be null or malformed. Schema libraries like Zod give static types and runtime guards from one contract. The footgun is using as instead of parse, silently reintroducing crashes.
Create a basic GET API endpoint in Next.js App Router
Tests App Router backend conventions. Create route.js in an app segment, export async GET with NextRequest and return NextResponse; route.js isolates the endpoint from page.js. Red flag: citing pages/api or raw Node res objects.
Implement OAuth 2.0 flow to get an access token for API requests
Tests your grasp of OAuth 2.0 grant-type selection and token lifecycle. Strong answers match the script context to client credentials or authorization code flow, detail the token endpoint exchange, and address refresh and expiry.
AWS SDK: Code That Operates Your Cloud
The AWS SDK turns AWS API calls into native code so your app can command S3 or DynamoDB directly. It handles auth, retries, and formatting automatically. The footgun: forgetting region or credentials causes silent failures that look like network errors.
Zod: TypeScript-First Schema Validation
Zod creates a single source of truth for your data's shape, providing both runtime validation and static TypeScript type inference from one definition. Use it to parse API inputs or form data, ensuring data is correct and typed.
Figma Vector Networks: Graphs, Not Just Chains
Vector networks are graphs, not just chains. Unlike traditional paths where a point connects only two lines, a vector network allows multiple lines to meet at a single vertex. This is Figma's engine for complex shapes.
Building Custom Figma Widgets with the Widget API
Build interactive objects on the Figma canvas using a React-like API. The Widget API uses components, functions, and hooks to create tools like polls or timers. The footgun is forgetting `useSyncedState`, which breaks your widget in multiplayer sessions.
Figma's Plugin API: Read and Write to the Canvas Tree
Think of a Figma file as a node tree. The Plugin API gives your JavaScript code read/write access to this tree to automate design tasks. Use it to batch-edit layers or generate content. The main footgun: files load dynamically, so you must use async APIs.
Figma REST API: Access Design Files as Structured Data
The Figma REST API treats your design files as structured JSON data, not just images. Use it to automate workflows like exporting assets, syncing design tokens, or posting comments. The main footgun is using the wrong base URL for Government vs.
OAuth 2.0: Delegated Access, Not Shared Passwords
OAuth 2.0 lets users grant limited access to their data without sharing passwords. It's used when a third-party app needs to read your Google Calendar. The common footgun is mistaking it for authentication (logging in); it's for authorization.
JSON Web Tokens (JWTs): Stateless API Passports
A JWT is a digitally signed passport for your web session, letting a server verify your identity without a database lookup on every request. It's used for stateless API authentication. The footgun: its payload is readable, so never store secrets there.
Handling CORS in Next.js API Routes
CORS isn't a global config; it's a per-route response header. To allow cross-origin requests to your API, you must manually set headers like `Access-Control-Allow-Origin` in your Route Handlers, including handling preflight OPTIONS requests.
Next.js: Dynamic API Segments for Flexible Endpoints
Think of dynamic API segments as URL templates. A single file like `app/api/users/[id]/route.ts` can handle requests for any user ID, from `/api/users/1` to `/api/users/99`. The footgun is forgetting to parse the ID, which is always a string.
NextResponse.json(): The Standard for API Responses in Next.js
NextResponse.json() is the standard way to send JSON from Next.js Route Handlers, like Express's res.json(). Use it in app/api routes to return data; it automatically sets the correct headers.
Route Handlers: Your Next.js App's API Endpoints
Route Handlers are lightweight API endpoints built into your Next.js app. Use them to serve JSON or handle form posts. The footgun is confusing them with Server Components; Route Handlers return data, not rendered UI.
MSW: Mock APIs at the Network Layer
Mock Service Worker intercepts API calls at the network level using a Service Worker, so your app makes real requests. Use it for consistent mocking in development, testing, and Storybook.
React Native NetInfo: Know Your Connection State
The NetInfo API is your app's network sensor, telling you if you're online and whether you're on WiFi or cellular. Use it to show an 'offline' banner or defer large downloads. The main footgun: `isConnected` only confirms a local link, not server reachability.
React Native's Share API: Use the Native Share Sheet
The React Native Share API opens the native OS share sheet, letting users share content like URLs or text. It provides a familiar UI with a single cross-platform method call.
Handling Permissions in React Native
A unified permissions API gives you one way to request device features, avoiding separate logic for iOS and Android. It's essential for apps needing the camera or location. The main footgun is forgetting to configure the native project files.
ActionSheetIOS: Native iOS Action Menus
ActionSheetIOS presents a native iOS menu sliding up from the bottom, offering users contextual choices. It's ideal for simple actions like "Delete" or "Save" and can also trigger the native share sheet.
WebSockets: A Persistent, Two-Way Connection
Think of a WebSocket as a dedicated phone line to a server, keeping the connection open for two-way conversation. It's ideal for real-time features like live chat or streaming stock tickers.
GraphQL Mutations: Writing Data to Your Graph
Think of a GraphQL mutation as a remote function call for writing data. Unlike REST, you declare what data you want back from the server in the same operation. Use it for creating, updating, or deleting data, like submitting a form or liking a post.
Get API bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.