What is an API callback URL?

I am combing the network and it seems that I am not inclined to the idea of ​​a callback. In my case, I have several callback URLs that I have to determine myself. Popular is the "Default Callback URL". What it is? Can you give an example in plain English?

+74
api callbackurl
Apr 28 '14 at 17:06
source share
5 answers

The callback URL will be called by the API method that you call after it finishes. Therefore, if you call

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

Then, when /foo complete, it sends a request to http://my.server.com/bar . The content and method of this request will vary - check the API documentation that you are accessing.

+56
Apr 28 '14 at 17:12
source share

Think of it like a letter. Sometimes you receive a letter, for example, asking you to fill out a form, and then return the form in an envelope with the specified address, which is in the original envelope in which the form was placed.

After you have completed filling out the form, you place it in the provided envelope and send it back.

CallbackUrl is like this return envelope. You basically say that I am sending you this data. As soon as you are done with this, I'm on this callbackUrl waiting for your answer. In this way, the API will process the data you sent, and then the callback will send you a response.

This is useful because sometimes it may take you years to process some data, and it makes no sense to force the subscriber to wait for an answer. For example, let's say your API allows users to send documents to it and scan them for viruses. Then you send the report after. Scanning may take 3 minutes. User cannot wait 3 minutes. In this way, you confirm that you have received the document and allow the caller to do other things while you are scanning, and then use callbackUrl when you are finished to tell them the result of the scan.

+14
Jan 31 '19 at 10:41
source share

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

Example

Diagram

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

The exact definition should be in the API documentation.

+6
Jan 30 '19 at 20:52
source share

Another use case might be something like OAuth, it may not be called directly by the API, instead, the callback URL will be called by the browser after authentication with the identity provider is complete.

Usually, after the end user enters the password for the username, the identity provider launches a browser that redirects to your “callback” URL with a temporary authorization code, for example

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

Then your application can use this authorization code to request an access token from an authentication provider that has a much longer life.

+1
Jan 31 '19 at 5:40
source share

This is a mechanism for calling the API in asynchronous mode. The sequence is as follows.

  1. your application calls the URL by passing the callback URL as a parameter
  2. The API responds with 20x http code (201, I think, but refer to the API documentation)
  3. API has been working on your request for a certain time
  4. The API calls your application to give you results at the callback URL.

This way you can call the API and tell your user that the request is “being processed” or “received”, for example, and then update the status when you receive a response from the API.

Hope this makes sense. -G

+1
Jan 31 '19 at 12:18
source share



All Articles