Skip to content

luisfcolon/py_restful_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Restful Client

No Maintenance Intended Coverage Status GitHub license GitHub issues

Silly little python restful client using Requests

Usage

Let's say you have the following restful endpoints:

# get all users
http://woot.com/users

# get single user, also can update this user
http://woot.com/users/1

# get all blog posts
http://woot.com/posts

# get single post, update post
http://woot.com/posts/123

To use the restful client:

client = RestfulClient()
client.base_url = 'http://woot.com'

# get

all_users = client.get('/users')
single_user = client.get('/users/1')

all_posts = client.get('/posts')
single_post = client.get('/posts/123')

# post, patch, put

user_data = {'firstname': 'luis'}

new_user = client.post('/users', data)
edit_user = client.patch('/users/1', data)
edit_user = client.put('/users/1', data)

# delete

deleted_user = client.delete('/users/1')

Using Basic Authentication is simple. You can create any auth object supported by Requests and pass it into the auth parameter.

auth = HTTPBasicAuth(username, password)
user_data = {'firstname': 'luis'}
new_user = client.post('/users', data, auth) 

# or

new_user = client.post('/users', data, auth=(username, password))

Error Handling

I removed all error handling from this version.

The client's only purpose is to make an api call and return a response. The application using this client should decide how it wants to handle any errors.

About

Python restful http client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages