sparkh2o
sparkh2o

Reputation: 264

Converting curl commands to http request interface

How would I convert the following curl commands from the Lyft api to http interfaced requests (so they can be executed over web like https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY)? If http requests translation is not possible, how would I integrate and process these curl commands in R?

 #Authentication code 
 curl -X POST -H "Content-Type: application/json" \
 --user "<client_id>:<client_secret>" \
 -d '{"grant_type": "client_credentials", "scope": "public"}' \
 'https://api.lyft.com/oauth/token'

 #Search query
 curl --include -X GET -H 'Authorization: Bearer <access_token>' \
 'https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167'

Upvotes: 4

Views: 27893

Answers (3)

Khachatur
Khachatur

Reputation: 989

ReqBin can automatically convert Curl commands to HTTP requests

An example of such request: Convert Curl to HTTP Request

Upvotes: 0

acityinohio
acityinohio

Reputation: 186

[Full disclosure: I'm a Developer Advocate at Lyft] I'm not very familiar with R, but could you integrate the responses/calls using the method described in this blog post?

https://www.r-bloggers.com/accessing-apis-from-r-and-a-little-r-programming/

Upvotes: 1

Jithu R Jacob
Jithu R Jacob

Reputation: 368

Hi you could use https://curl.trillworks.com/ to convert curl commands to the language of your choice or you could use lyft SDK's (for Python use https://pypi.python.org/pypi/lyft_rides).

Here is the corresponding Python version

import requests

headers = {
    'Content-Type': 'application/json',
}

data = '{"grant_type": "client_credentials", "scope": "public"}'

requests.post('https://api.lyft.com/oauth/token', headers=headers, data=data, auth=('<client_id>', '<client_secret>'))

From this post request you will get access token that has to be used for subsequent requests.

headers = {
    'Authorization': 'Bearer <access_token>',
}

requests.get('https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167', headers=headers)

Note: I haven't tested this as I am unable to create a lyft developer account so there might be some minor changes in the code given here.

Upvotes: 3

Related Questions