wasAsked.

difference between web api vs rest

PwC · Full Stack Developer · technical

Published

Year not specified · Software Engineering

Community answers

Posted by wasAsked editorial collection

They are related but not the same kind of thing. REST - An architectural style for distributed systems (Roy Fielding, 2000), defined by constraints: client–server, statelessness, cacheability, a uniform interface (resources identified by URIs, standard methods, self-descriptive messages, hypermedia), layered system, and optional code on demand. - It is technology-independent: it describes how to design an API, not how to build it. Web API - A general term for any API accessible over the web via HTTP. It may or may not follow REST principles. - Can be RESTful, RPC-style (POST /api/calculateTax), SOAP-based, GraphQL, gRPC-Web and so on. - In the .NET world, "ASP.NET Core Web API" is also the name of the framework and project type used to build HTTP APIs. You can build RESTful services with it, but nothing forces you to. Relationship - REST is a set of design principles; a Web API is an implementation exposed over HTTP. - A RESTful API is a Web API that follows REST constraints. Not every Web API is RESTful. Examples RESTful Web API: GET /api/orders/42 POST /api/orders PUT /api/orders/42 DELETE /api/orders/42 Resources as nouns, HTTP methods for actions, meaningful status codes (201, 404, 409), stateless requests and cacheable GET responses. Non-RESTful Web API: POST /api/GetOrderById { "id": 42 } POST /api/DeleteOrder { "id": 42 } Verbs in URLs, everything through POST, and errors returned as 200 OK with an error flag. Other comparison points - Protocol: REST is not tied to HTTP in theory (though almost always uses it); a Web API by definition uses web protocols. - Format: REST does not mandate JSON; Web APIs commonly use JSON or XML. - State: REST requires statelessness; a generic Web API might use server-side sessions. Interview summary: "REST is an architectural style; Web API is the broader concept of exposing functionality over HTTP — and in .NET, the framework used to build such services. We use ASP.NET Core Web API to build APIs that follow REST principles."

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics