HTTP Response Codes — With Code Snippets for JS, Python & nginx
All 34 status codes · Search · Filter · Snippets · cURL Tester · Favorites
HTTP response codes reference with production-ready code snippets. Every status code includes examples in JavaScript fetch, Axios, Express.js, Python Flask, and nginx configuration. Use the snippet tabs in the detail panel to copy the exact code for your stack.
Click any status code to see full details, code snippets, and usage guide
Frequently Asked Questions
How do I handle different HTTP status codes in JavaScript fetch?
fetch() does not throw on 4xx/5xx — check response.ok (true for 200–299) or response.status directly. Use: if (!response.ok) { const err = await response.json(); throw new Error(err.message); }. For specific handling: if (response.status === 401) { redirect to login } else if (response.status === 429) { wait Retry-After, then retry }.
How do I return a specific HTTP status in Express.js?
Use res.status(code).json(body): res.status(200).json({data}), res.status(201).json({created}), res.status(204).send(), res.status(400).json({error}), res.status(404).json({message: "Not found"}). For async error handling, use next(err) with a global error handler that maps error types to status codes.
How do I return HTTP status codes in Python Flask?
Return a tuple: return jsonify({"data": result}), 200. Or use abort(): from flask import abort; abort(404). Or use make_response: response = make_response(jsonify(data), 201). For error handlers: @app.errorhandler(404) def not_found(e): return jsonify({"error": "Not found"}), 404.
How do I configure redirect status codes in nginx?
For 301: return 301 https://new-domain.com$request_uri; For 302: return 302 /new-path; For custom error pages: error_page 404 /404.html; error_page 500 502 503 504 /50x.html; For proxy pass error handling: proxy_intercept_errors on; error_page 502 @fallback.
How do I check an HTTP status code with curl command line?
Use curl -I (HEAD request) or curl -o /dev/null -w "%{http_code}" URL. For full verbose output: curl -v URL. For following redirects: curl -L URL. For timeout: curl --max-time 10 URL. Example: curl -o /dev/null -s -w "%{http_code}" https://api.example.com/endpoint — prints just the status code.
How do I test HTTP status codes in Postman or Thunder Client?
In Postman, the status code appears in the top-right of the response panel. Use Tests tab to assert: pm.response.to.have.status(200). In Thunder Client (VS Code), status shows in response header. For automated testing, use Jest + supertest: expect(response.status).toBe(201), or Cypress: cy.request("/api").its("status").should("eq", 200).