Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra_data parameter + Add request_url property in UnirestResponse #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ocervell
Copy link

@ocervell ocervell commented Dec 12, 2016

Pretty often when I make asynchronous requests I need two things that are commonly implemented in asynchronous request libraries:

  • Access the request URL in the callback function.
  • Access extra data that I pass with my request and that I have to access in the callback.

Now I love using unirest because it's so simple and beautiful, but those are limitations that are too important to pass on.

A simple example is for logging / reporting purposes, when you need to log the request URL in the response and record the HTTP code .
I add an extra_data and request_url properties in the UnirestResponse to tackle these two problems.

Example use:

import unirest
import logging
log = logging.getLogger(__name__)

def callback(r): 
  task_id = r.extra_data['task_id']
  entry = "Task number: {0} | Request url: {1} | Response code: {2}".format(task_id, r.request_url, r.code)
  log.info(entry)

extra_data = {'task_id': 1}
unirest.get('http://unirest.io', callback=callback, extra_data=extra_data)

@ocervell
Copy link
Author

Any update on this ? I feel like this is a must-have for an asynchronous request lib

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Olivier Cervello seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants