Skip to main content

An elegant RESTful client based on requests.

Project description

Requests-REST: A RESTful client based on requests

This library intends to provide an elegant RESTful client.

Installation

pip install requests-rest

Usage example

base_url = 'https://httpbin.org/'

new_name = 'aponder'
new_email = 'i@aponder.top'
new_user = {
    'name': new_name,
    'email': new_email,
}
update_user = new_user.copy()
update_user.update({'name': f'new {new_name}'})

# print(resource_user.list().json())
# print(resource_user.create(new_user).json())
# print(resource_user.update(1, new_user).json())
# print(resource_user.patch(1, new_name).json())
# print(resource_user.patch(1, new_email).json())
# print(resource_user.delete(1).json())

resource_client = Client(base_url, debug=True)
Users = resource_client('users')

users_creating = Users.create(new_user)
print(users_creating.response)

users_listing = Users.list(page=1, page_size=10)
print(users_listing.response)

users_detailing = Users.detail(1)
print(users_detailing.response)

users_updating = Users.update(2, update_user)
print(users_updating.response)

users_partial_updating = Users.partial_update(3, update_user)
print(users_partial_updating.response)

users_deleting = Users.delete(4)
print(users_deleting.response)

# extra actions
Users.login = Users.make_plural_action('login')
credentials = {'username': 'root', 'password': 'root'}
print(Users.login(credentials).response)

Users.disable = Users.make_single_action('disable')
print(Users.disable(2).response)

# resource combination
Blogs = resource_client('blogs')
UsersBlogs = users_detailing(Blogs)

new_blog = {'title': 'hello'}
print(UsersBlogs.create(new_blog).response)
print(UsersBlogs.list(page=2, page_size=20).response)
print(UsersBlogs.delete(10).response)
print(UsersBlogs.update(10, new_blog).response)
print(UsersBlogs.partial_update(10, new_blog).response)
print(UsersBlogs.delete(10).response)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests-rest-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

requests_rest-0.3.0-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file requests-rest-0.3.0.tar.gz.

File metadata

  • Download URL: requests-rest-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for requests-rest-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ec544499e7020da3e0e8a98a62510ffc08037f45a6298a9d332a5cb0bc6de854
MD5 29546cff485d0c40a0db59ca65763831
BLAKE2b-256 bc836cea5c3fcf2d81ff7b155944acd1262f539217c12099bc2305212b3fb896

See more details on using hashes here.

File details

Details for the file requests_rest-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: requests_rest-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for requests_rest-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1aaba1dd2943ffe6c6d87282baa8aae954972ca76970cf2cae36451e6c66d5b6
MD5 000f7d8a67735d90c24f9b37a46962b8
BLAKE2b-256 716def42ceb12ace48c34b30456e8b6027bb279d8839e3d381803fa97c93021c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page