Skip to main content

Boilerplate-free way for creating libs for REST APIs

Project description

REST API lib creator

REST API lib creator is a boilerplate-free way for creating libs for RESTful APIs (specially the ones created using Django REST framework - but certainly adaptable for other frameworks).

NOTES: 1 - This is a port for a personal project I made for myself. It may or may not solve your needs (it solves mine). 2 - This is still alpha. I opened this on GH just so I can see if this is something I should improve (or not).

Click here to see the full documentation.

Examples:

  • The bare minimum for creating your own lib:
from rest_api_lib_creator.core import ViewsetRestApiLib


class User(ViewsetRestApiLib):
    base_api_url = 'http://super.cool/api/users'
  • With this you can play around with your API:
users = User.list()  # Triggers a requests.get with url http://super.cool/api/users
isinstance(users[0], User)

user = User.create(first_name='Filipe', last_name='Waitman', email='filwaitman@gmail.com', photo=open('image.png', 'rb'))  # Triggers a requests.post with url=http://super.cool/api/users and data={'first_name': 'Filipe', 'last_name': 'Waitman', 'email': 'filwaitman@gmail.com'} and files={'photo': <file binary content>}
isinstance(user, User)
print(user.id)  # prints the user id (assuming the API returned this field)
print(user.first_name)  # prints the user first name (assuming the API returned this field)
user.first_name = 'New name'
user.save()  # Triggers a requests.patch with url=http://super.cool/api/users/<user-id> and data={'first_name': 'New name'}

user.delete()  # Triggers a requests.delete with url=http://super.cool/api/users/<user-id>
  • If your resource return other nested resources you can parse them as well:
class Pet(ViewsetRestApiLib):
    base_api_url = 'http://super.cool/api/pets'
    nested_objects = {
        'owner': User,
    }


pet = Pet.retrieve('pet-id')
isinstance(pet, Pet)
isinstance(pet.owner, User)

You can see all possible customizations here (someday I'll improve this doc).

Special thanks:

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

rest-api-lib-creator-0.1.0.tar.gz (17.6 kB view hashes)

Uploaded Source

Built Distributions

rest_api_lib_creator-0.1.0-py3.6.egg (4.2 kB view hashes)

Uploaded Source

rest_api_lib_creator-0.1.0-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

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