What is a callback URL in relation to an API?

TerminologyCallbackurl

Terminology Problem Overview


I've been scouring the net, and can't seem to wrap my head around the idea of a callback URL. In my case I have a few callback URLs that I have to define myself. A popular one is a "default callback URL". What is this exactly? Can you give an example in plain english?

Terminology Solutions


Solution 1 - Terminology

A callback URL will be invoked by the API method you're calling after it's done. So if you call

POST /api.example.com/foo?callbackURL=http://my.server.com/bar

Then when /foo is finished, it sends a request to http://my.server.com/bar. The contents and method of that request are going to vary - check the documentation for the API you're accessing.

Solution 2 - Terminology

Think of it as a letter. Sometimes you get a letter, say asking you to fill in a form then return the form in a pre-addressed envelope which is in the original envelope that was housing the form.

Once you have finished filling the form in, you put it in the provided return envelope and send it back.

The callback URL is like that return envelope. You are basically saying, "I am sending you this data; once you are done with it, I am listening on this callback URL waiting your response." So the API will process the data you have sent then look at the callback to send you the response.

This is useful because sometimes you may take ages to process some data and it makes no sense to have the caller wait for a response. For example, say your API allows users to send documents to it and virus scan them. Then you send a report after. The scan could take maybe 3 minutes. The user cannot be waiting for 3 minutes. So you acknowledge that you got the document and let the caller get on with other business while you do the scan, then use the callback URL when done to tell them the result of the scan.

Solution 3 - Terminology

If you use the callback URL, then the API can connect to the callback URL and send or receive some data. That means API can connect to you later (after API call).

Example

Diagram

  1. YOU send data using request to API
  2. API sends data using second request to YOU

Exact definition should be in API documentation.

Solution 4 - Terminology

It's a mechanism to invoke an API in an asynchrounous way. The sequence is the following

  1. your app invokes the url, passing as parameter the callback url
  2. the api respond with a 20x http code (201 I guess, but refer to the api docs)
  3. the api works on your request for a certain amount of time
  4. the api invokes your app to give you the results, at the callback url address.

So you can invoke the api and tell your user the request is "processing" or "acquired" for example, and then update the status when you receive the response from the api.

Hope it makes sense. -G

Solution 5 - Terminology

I'll make this pretty simple for you. When a transaction is initiated, it goes under processing stage until it reaches the terminal stage. Once it reaches the terminal stage, the transaction status is posted by the payment gateway to the callback url which generally the merchants use as a reference to show the success/failure page to the user. Hope this helps?

Solution 6 - Terminology

Another use case could be something like OAuth, it's may not be called by the API directly, instead the callback URL will be called by the browser after completing the authencation with the identity provider.

Normally after end user key in the username password, the identity service provider will trigger a browser redirect to your "callback" url with the temporary authroization code, e.g.

https://example.com/callback?code=AUTHORIZATION_CODE

Then your application could use this authorization code to request a access token with the identity provider which has a much longer lifetime.

Solution 7 - Terminology

Here's a common example of how a callback works - something that most people who've bought online probably have experienced. You've made a purchase on your favorite website and clicked the "Submit" button. Chances are you'll be sent to an external service that handles the payment processing (like PayPal) where you confirm your order, or just wait while you watch the word "processing..." blink on the screen. After the transaction completes you are directed back to the original shopping site. The page that you see is the callback URL. Though you didn't know it, you left your favorite online store's website during the processing, and the external site you visited returned you back to it. Barring any glitches you should see the page the store wanted you to see after an order. It might be a thank you page, or other page with order confirmation information, next steps, or their home page. It may vary depending on what you ordered, when you ordered, and how you ordered.

Basically a callback URL gives directions to an external system on where to go next. What is at that URL could be anything. It doesn't have to be a static URL. More

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionApathyBearView Question on Stackoverflow
Solution 1 - TerminologyEric SteinView Answer on Stackoverflow
Solution 2 - TerminologyTaf MunyurwaView Answer on Stackoverflow
Solution 3 - TerminologyjiwopeneView Answer on Stackoverflow
Solution 4 - TerminologyGiuseppe BView Answer on Stackoverflow
Solution 5 - TerminologySwagat sahooView Answer on Stackoverflow
Solution 6 - TerminologyHainan ZhaoView Answer on Stackoverflow
Solution 7 - TerminologyJuntaView Answer on Stackoverflow