How do you build and authenticate a REST API?
Answer
Clear, interview-ready explanation
Build a REST API around clear resource-oriented routes, appropriate HTTP methods and status codes, request validation, authorization policies, and consistent JSON responses. Use API resources to control the public response shape, pagination for lists, and versioning or compatibility rules when the API has external consumers.
For authentication, choose Laravel’s built-in cookie/session services for a traditional first-party web application, Sanctum for first-party SPAs, mobile clients, and simple API tokens, or Passport when OAuth2 features are truly required. Authentication proves identity; policies and gates must still enforce access to each resource. Protect production APIs with rate limits, logging, tests, and secure transport.