0

I have a rest server that can be called e.g. with:

http://localhost:8080/myserver/rest/books/t1.json

I want to know how can I use from django rest framework as a client and call my rest server?

2
  • Do you want to provide a second API that calls the first API before delivering results or are you just looking to call an API programmatically? Commented Nov 20, 2014 at 18:35
  • I want to call programmatically the rest server and deserialize json/xml/yaml result. Commented Nov 20, 2014 at 18:43

1 Answer 1

1

Django Rest Framework is for creating REST APIs, not consuming them. To simply call a REST API from Django/Python you can do the following using json and urllib2 which are standard:

import json
import urllib2

data = json.load(urllib2.urlopen('http://myapi.com/'))

or you can use the 3rd party library requests:

import requests
r = requests.get('http://myapi.com/')
r.json()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.