user3342812
user3342812

Reputation: 343

How is web service different from api?

I am learning to develop web services. From what I know there are two methods 1. SOAP and 2. REST. Soap is communicating mostly using XML while REST is HTTP request. Can I have external API like google api, twitter api, or may be imdb movie api as my web service ? Most of these API are restAPI so does that mean if I develop a movie info web service it will be restful? I am currently learning to create a web service which will return movie information using imdb http request to its api. Can a web service internally have different external api like imdb api which is rest ?

Upvotes: 1

Views: 192

Answers (1)

Michael Aaron Safyan
Michael Aaron Safyan

Reputation: 95439

Your confusion is understandable. There are a lot of related but slightly different terms. To clarify:

API The application programmer interface (or API) is the "contract" between a provider of some functionality and a consumer of some functionality. The API includes the inputs, their types, and any preconditions on the input, the expected output and any postconditions on the output, the failure modes, and any other information necessary to successfully consume the functionality (such as the function signature in the context of programming language APIs or the request path in the context of web APIs).

Service The API is notably not a particular implementation. It is a specification that allows for a provider or consumer of some functionality to develop their components independently and successfully integrate with each other (or with alternative implementors/consumers). A service, on the other hand, is a specific implementation of an API. For example, Feedly and the (now defunct) Google Reader are/were services that both implement the same Google Reader API.

As for SOAP vs REST, both SOAP and REST use HTTP. However, they take slightly different approaches/styles to the structure of the requests and responses. A web API is not, by definition, RESTful simply for being an API. A web API is RESTful if it follows the principles of REST. In particular, an API is RESTful if URLs correspond to resources, and the verbs that act on these resources are the HTTP methods (like GET, PUT, POST, and DELETE). For example, in a RESTful API, one retrieves a resource by using "GET", appends to it with "PUT", and ovewrites it with "POST". For modifying lists of items, one typically has a URL referencing both a particular element as well as the list of elements. Many so-called "REST" APIs are not really REST in the strictest, purest sense of the term. For example, many Google APIs share many properties/ideas of REST but often include verbs in the path of the URL for indicating the action performed (whereas REST, in the strictest sense, would not allow for this, since the URLs are supposed to represent nouns, only, with HTTP methods as the only verbs).

Finally, to answer the last question, yes it is possible to have a different internal vs external API. That being said, whether the term "API" truly applies to the internal version is debatable and depends on whether there are separate internal "consumers" and "providers" of that functionality. If the internal version is just whatever the internal implementation happens to be, whether it can be labeled as an "API" or not is somewhat up for debate.

Upvotes: 1

Related Questions