An API is the general concept; a REST API is one specific style of API. API (Application Programming Interface) - Any defined way for one piece of software to communicate with another: a contract describing the requests you can make and the responses you get. - APIs exist at many levels: - Library APIs: methods of a class or package (for example .NET's List<T>.Add). - Operating system APIs: Windows API, POSIX. - Browser APIs: fetch, localStorage, Geolocation. - Web APIs: services accessed over a network, using REST, SOAP, GraphQL, gRPC, WebSockets and more. REST API (RESTful API) - A web API that follows the REST (Representational State Transfer) architectural style, usually over HTTP with JSON. - Key principles: - Resources identified by URLs: /customers/42/orders. - Standard HTTP methods with clear meaning: GET (read), POST (create), PUT (replace), PATCH (partial update), DELETE (remove). - Statelessness: every request contains all information needed (for example an authentication token); the server keeps no session between requests. - Standard status codes: 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Internal Server Error. - Cacheable responses (Cache-Control, ETag) and a uniform interface. Example GET https://api.shop.com/products/15 Response: 200 OK { "id": 15, "name": "Wireless Mouse", "price": 799 } Other API styles for comparison - SOAP: XML messages with a strict contract (WSDL), common in older enterprise and banking integrations. - GraphQL: a single endpoint where clients query exactly the fields they need. - gRPC: high-performance binary protocol using Protocol Buffers, popular between microservices. - RPC-style HTTP APIs: endpoints named after actions (POST /api/createOrder) — web APIs, but not RESTful. So: every REST API is an API, but not every API is a REST API. Why REST is popular - Simple, uses well-known HTTP features, works in any language, easy to cache and debug with tools like Postman, curl and browser developer tools. - Fits naturally with JSON and web or mobile clients. When another style may be better - GraphQL for complex frontends that need flexible data shapes. - gRPC for internal service-to-service calls requiring low latency and streaming. - Messaging (queues, events) for asynchronous workflows. Interview summary: "API is the umbrella term for any interface between software components. A REST API is a web API designed according to REST constraints — resource URLs, HTTP methods, statelessness and standard status codes."
Ravindra Wadile · · 0 likes