# HackerEarth API v2: Introducing asynchronous callbacks

DevFeed: [HackerEarth API v2: Introducing asynchronous callbacks](<https://devfeed.tech/articles/hackerearth-api-v2-introducing-asynchronous-callbacks-19983.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2013/09/09/hackerearth-api-v2-asynchronous-callbacks/>)

Published: 2013-09-09T00:00:00Z

Content type: article

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [API](<https://devfeed.tech/topics/api.md>), [JSON](<https://devfeed.tech/topics/json.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [payload](<https://devfeed.tech/topics/payload.md>), [C](<https://devfeed.tech/topics/c.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [developer](<https://devfeed.tech/tags/developer.md>), [http](<https://devfeed.tech/tags/http.md>), [json](<https://devfeed.tech/tags/json.md>), [payload](<https://devfeed.tech/tags/payload.md>), [post](<https://devfeed.tech/tags/post.md>)

## AI overview

HackerEarth API v2 introduces asynchronous callbacks for code compilation and execution. Clients receive an immediate confirmation, while the completed evaluation arrives later as POST data containing a JSON response in the payload parameter.

## Source excerpt

We had already published HackerEarth API v1 in February, 2012 at http://developer.hackerearth.com. The API v1 was synchronous in nature. This means that your request kept hanging until the code evaluation was done and response was received. This seriously limited anyone from writing robust applications using the API. We have been using the asynchronous API for a long time ourselves at HackerEarth for processing all the code submissions. It's fast, it's robust and works flawlessly. Today, we are making the async API public. There is not a major change in the way API request is done, if you have already checked out the synchronous API v1. Now, you get a confirmation response as soon as you do the request. The actual response containing the code evaluation data arrives later at the callback as POST data, with the response contained in 'payload' POST parameter. The response format is always same and in JSON format. Below is a technical description of how the Asynchronous API works. The API defines the following endpoints: http://api.hackerearth.com/code/compile/ http://api.hackerearth.com/code/run/ If you haven't already got your secret key, register here. To make an asynchronous request, now you just need to pass 1 as a value to 'async' parameter, along with other required parameters. import urllib COMPILE_URL = 'http://api.hackerearth.com/code/compile/' RUN_URL = 'http://api.hackerearth.com/code/run/' CLIENT_SECRET = '5db3f1c12c59caa1002d1cb5757e72c96d969a1a' source = open('sample.c').read() lang = 'C' post_data = { 'client_secret': CLIENT_SECRET, # Asynchronous mode on 'async': 1, 'source': source, 'lang': lang, 'time_limit': 5, 'memory_limit': 262144, # Id to keep track of request 'id': 123, # Callback URL where processed response will later arrive # - this response is same as the response received in # synchronous API request. 'callback': 'http://example.com/receive-hackerearth-response/' } post_data = urllib.urlencode(post_data) response = urllib.urlopen(RUN_URL,