-4

What is an Api - here can you give an example. I heard that an api is used to communicate between two Applications. But ifwe have only one application then?

When I referred to stackoverflow for what is an Api?- I got an information that an api helps a program to communicate with another program. There was an example - In online shopping website we provide credit card details and thus Online shopping is communicating with Credit card company using an API.

I understood this example. But whenever someone speaks about an API in a single App I confuse. Confusion is if app is single then to whom will it communicate to ?(In online shopping app it was communicating to a credit card app). Let's say I have a basic CRUD application(where we can Add student, update, retrieve and delete the student). Will it be an API? If yes then where?

I tried going through- What exactly is the meaning of an API?

Alok Kumar
  • 13
  • 3
  • It's a contract. You say, "do this and you can add a student" "do this and you can update a student" etc. Then when you or somebody else writes a client. They can look at your API and know what they need to do. – matt Feb 15 '23 at 10:45
  • Here in a class if I write something like @PostMapping("/users") public ResponseEntity createUser(@Valid @RequestBody User user) { User savedUser=userDaoService.saveTheUser(user); URI location=ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(savedUser.getId()).toUri(); return ResponseEntity.created(location).build(); } Then is it an api? – Alok Kumar Feb 15 '23 at 10:49
  • It could be considered a pretty bad API, but sure. You've created an endpoint that somebody can access by using a post method. An API should be descriptive to the user/consumer. eg "Create users by making a POST request with the following attributes." the term refers to the collection of actions you can do. Like the java API, you know you can write java code and expect a certain action to happen. The javadocs define the API. You don't need to know what happens behind the scenes. – matt Feb 15 '23 at 10:55
  • Like the online shopping. Paypal has an API, you read their documentation to learn how you can access their webservices to perform actions. "How can I accept money to pay for my service.". Then you find the tools that Paypal has made available. "Action: Send a post request here with these attributes to setup a payment. Response: You get a transaction code for when the user returns to your site." – matt Feb 15 '23 at 10:59
  • 1
    *I tried going through- What exactly is the meaning of an API?* Yes, and what are you then still missing? It seems to me that there are good explanations there. And also examples. – Ole V.V. Feb 15 '23 at 11:00
  • To continue paypal example. You might say, "Why am I writing http requests in java, this is cumbersom?" So you would then ask, "Does paypal have a java api" so you can just write code in java without worrying about get/post etc. – matt Feb 15 '23 at 11:02

2 Answers2

0

API stands for Application Programming Interface. Let's understand it in layman terms.

Interface tells us how to establish the connection (think in terms of request parameters, URI etc). Application in API stands for the application this API will allow communication with and Programming means that you need to use computer programs.

It is like an address with instructions. URI is the address and HTTP verb, request parameters etc. are the instructions.

Now to your other question. What does it mean when there's only one application involved. Well it means that you can connect to that application using this API, if ever you have to. It doesn't mandate you to connect to it. After all, there's no point in creating an application with no endpoints for the users to connect to that application and use it.

Lalit Mehra
  • 1,183
  • 1
  • 13
  • 33
-1

API is a Web Service.

Example : Here is an API that gives you the list of cities in France by Zip code (in my example it is 79000, you can switch to see other results)

https://geo.api.gouv.fr/communes?codePostal=79000

To fully understand API, look this image

enter image description here

mbyou
  • 104
  • 1
  • 7
  • The first sentence of this is obviously wrong, as an example the Win32 API doesn't involve the web in any way. – PeterJ Feb 15 '23 at 11:38