When to use an API and when a Web Service? [closed]

0

I am currently in a project in which I have to perform a web service or an API, but not having much knowledge of these I do not know what to use, the client that will use it has to pass certain parameters and with these Parameters the web service or the api that I have to perform has to go to insert, update and delete a database and depending on the result of the same return a JSON in which shows if the transactions were satisfactory and if not inserted return the error for which he could not insert.

I have to do it with Java.

Thanks!

    
asked by Gustavo Oliva 11.12.2018 в 18:16
source

2 answers

3

TL; TR (summary)

Whenever you need to program an interface for communication between two or more systems, you will have an API.

  • A web service is an API that is used for communication between electronic devices through the web (originally with the XML format).
  • An API is a programming interface (which is not always exposed to the web) and is not limited to a format for data transfer.
  

When to use an API and when a Web Service?

When the business requirement requires it or you consider it necessary.

What are web services?

Computer resources are its main objective is the communication between different teams and as the name suggests; through a network.

Such communication is achieved through the use of the XML format for data transfer.

What is an API?

Its acronym corresponds to the English Application Programming Interface (Application Programming Interface, in Spanish) and the API is a door within a system that allows us to interact with functionalities exposed through this interface.

Communication is not limited to a format like XML, it's free.

  

f. interface inform : Connection, physical or logical, between a computer and the user, a peripheral device or a communication link. - RAE .

Conclusions

A web service is an API, since it exposes the interface for two computers / systems to communicate, but as long as it is in XML.

On the other hand, an API is not always a web service, since it does not limit its communication to the XML format.

Exemplify:

  • (Interface) So that a stereo can emit sound, pulses are sent through the cable that leads to the speaker, but this cable is connected to the stereo. This connection (horn-stereo) is an interface and has been manufactured with certain industrial standards that will not guarantee its operation regardless of the manufacturer of the horn.
  • (Web service / API) A mobile application reports to a banking site the operations performed by a user in real time, its communication is through XML.
  • (JSON API) Another application is responsible for notifying the user of the browser (through alerts) about the new promotions of an X store, such communication is established by JSON format.
  • (API) A programmer performs an application to clean temporary data, cache, etc ... for Z operating system, but also offers more advanced features such as recovery of deleted files; for this, it uses (at a low level) the functions that the hard disk offers to achieve it (interface).
  • (Interface) JavaScript, CSS and HTML interact with each other thanks to the interface provided by the engine of each web browser.
  • If your communication will be in JSON, you will be building a JSON API and it will be called an exposed API, if it will be public or it will be accessed from the web (the word "exposed" does not mean that there is no access control system at the level logical).

    If what you want is to implement architectures for the communication of your APIs, I recommend you see about:

    • SOA: Software Oriented Architecture.
    • ROA: Resource Oriented Architecture.
    • REST: Respresentational Estate Transfer.

    References:

    answered by 11.12.2018 / 19:18
    source
    1

    A request to an API does not stop being a web request to use. You will have to use requests with the appropriate verbs (get, put, post, ...) http depending on what you are going to do in the bbdd. On the backend (API) side, instead of returning an html, a JSON is returned, which the client can format and format. You can generate APIS in many ways, but I prefer Nodejs and Express, for the database MongoDB is usually used but this depends on the data and its relationships, in case it is a realtime application you should use Firebase. Also, if it is not an open and public API you will have to use middlewares to authenticate users. If it's your first time, I'll let you know it's going to take a while to develop it.

    You say it has to be in java, but the microservices are independent of the clients. No matter what language the client is programmed into since you manage JSON documents, I would avoid using Java and convince them of it. Otherwise the concepts above are the same.

        
    answered by 11.12.2018 в 18:35