All Projects → sayanarijit → RESTEasy

sayanarijit / RESTEasy

Licence: MIT license
REST API calls made easier

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to RESTEasy

Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (+2175%)
Mutual labels:  http-client, requests, rest-client
Php Curl Class
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
Stars: ✭ 2,903 (+24091.67%)
Mutual labels:  http-client, api-client, requests
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (+100%)
Mutual labels:  http-client, api-client, rest-client
apiron
🍳 apiron is a Python package that helps you cook a tasty client for RESTful APIs. Just don't wash it with SOAP.
Stars: ✭ 106 (+783.33%)
Mutual labels:  api-client, requests, rest-client
Python Simple Rest Client
Simple REST client for python 3.6+
Stars: ✭ 143 (+1091.67%)
Mutual labels:  http-client, requests, rest-client
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+5525%)
Mutual labels:  http-client, requests, rest-client
NClient
💫 NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Stars: ✭ 25 (+108.33%)
Mutual labels:  http-client, api-client, rest-client
Uplink
A Declarative HTTP Client for Python
Stars: ✭ 824 (+6766.67%)
Mutual labels:  http-client, api-client, requests
Frequest
FRequest - A fast, lightweight and opensource desktop application to make HTTP(s) requests
Stars: ✭ 130 (+983.33%)
Mutual labels:  json-api, http-client, rest-client
restofus
Restofus - a cross-platform (REST) API client.
Stars: ✭ 18 (+50%)
Mutual labels:  http-client, api-client, rest-client
YuiAPI
一个浏览器API测试客户端,API文档生成器,支持chrome/firefox/新版edge
Stars: ✭ 25 (+108.33%)
Mutual labels:  api-client, rest-client
drowsy
😪 Lazy integrations tool for RESTful interfaces to aid POC development and streamline integrations
Stars: ✭ 19 (+58.33%)
Mutual labels:  api-client, rest-client
go-json-spec-handler
Simple JSON API Spec Compatibility in Golang
Stars: ✭ 41 (+241.67%)
Mutual labels:  json-api, api-client
dynamic-cli
A Modern, user-friendly command-line HTTP client for the API testing, and if you're stuck - Search and browse StackOverflow without leaving the CLI
Stars: ✭ 151 (+1158.33%)
Mutual labels:  http-client, api-client
DummyJSON
DummyJSON provides different types of REST Endpoints filled with JSON data which you can use in developing the frontend with your favorite framework and library without worrying about writing a backend.
Stars: ✭ 213 (+1675%)
Mutual labels:  json-api, api-client
Proxy
The type-safe REST library for .NET Standard 2.0 (NetCoreStack Flying Proxy)
Stars: ✭ 40 (+233.33%)
Mutual labels:  http-client, rest-client
JSON-API-Client
Abstract client-side php implementation of the json api specification (jsonapi.org)
Stars: ✭ 17 (+41.67%)
Mutual labels:  json-api, api-client
lhs
⚛️ REST services accelerator: Rails gem providing an easy, active-record-like interface for http (hypermedia) json services
Stars: ✭ 130 (+983.33%)
Mutual labels:  json-api, http-client
unity-simple-http
A dead simple HTTP client for Unity3D
Stars: ✭ 32 (+166.67%)
Mutual labels:  http-client, rest-client
resto
🔗 a CLI app can send pretty HTTP & API requests with TUI
Stars: ✭ 113 (+841.67%)
Mutual labels:  http-client, requests

RESTEasy

REST API calls made easier

PyPI version Python versions Build status Code coverage

Installation

pip install resteasy

Usage and examples

Import

from resteasy import RESTEasy, json

api = RESTEasy(endpoint='https://api.example.com',
               auth=('user', '****'),
               verify=False, cert=None, timeout=None,
               allow_redirects=True,
               encoder=json.dumps, decoder=json.loads, debug=False)
               
# optional timeout
api.timeout = 60

Example 1: GitHub Jobs

api =  RESTEasy(endpoint='https://jobs.github.com')

positions = api.route('positions.json')

positions.get(description='python', full_time=1)
# or
positions.do('GET', {'description': 'python', 'full_time': 1})

# GET https://jobs.github.com/positions.json?description=python&full_time=1

Example 2: All methods: GET, POST, PUT, PATCH, DELETE

from resteasy import RESTEasy

api = RESTEasy(endpoint='https://jsonplaceholder.typicode.com')

posts = api.route('posts')

### GET (fetch resources)
posts.get()
posts.get(userId=1)
posts.route(1).get()

### POST (create a resource)
posts.post(title='foo', body='bar', userId=1)

### PUT & PATCH (update a resource)
posts.route(1).put(id=1, title='foo', body='bar', userId=1)
posts.route(1).patch(title='foo')

### DELETE (delete a resource)
posts.route(1).delete()

Example 3: Chuck Norris jokes

from __future__ import print_function
from resteasy import RESTEasy

api = RESTEasy(endpoint='https://api.chucknorris.io')


### Print a random joke
jokes = api.route('jokes')
random = jokes.route('random')
print(random.get())

# GET https://api.chucknorris.io/jokes/random


### Get all categories
categories = jokes.route('categories').get()
print(categories)

# GET https://api.chucknorris.io/jokes/categories


### Print a random joke from each category
for category in categories:
    random_joke = random.get(category=category)
    print(category, ':', random_joke['value'])

    # GET https://api.chucknorris.io/jokes/random?category=<category>

Example 4: Using custom decoder: Parsing MyAnimeList HTML content

from resteasy import RESTEasy
from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    '''Custom HTML parser'''
    
    def handle_starttag(self, tag, attrs):
        '''Overriding abstract method'''
        if tag == 'title' and not self.found:
            self.found = True

    def handle_data(self, data):
        '''Overriding abstract method'''
        if self.found and self.anime is None:
            self.anime = data
    
    def parse(self, content):
        '''Parse content and return object'''
        self.found = False
        self.anime = None
        self.feed(content)
        title = self.anime.strip().replace(' - MyAnimeList.net', '') if self.found else None
        return dict(title=title)

parser = MyHTMLParser()

api = RESTEasy(endpoint='https://myanimelist.net', decoder=parser.parse)

### One way
api.route('anime/1').get()

### Another way
api.route('anime', 1).get()

### Yet another way
api.route('anime').route(1).get()

### This is the last way I swear
api.route('anime').route(1).do(api.GET)

### Just kidding...
api.route('anime').route(1).request(api.GET).json()

# GET https://myanimelist.net/anime/1

Debugging

To enable debugging just pass or set debug=True

api.debug = True

Once debugging is set to 'True', Every HTTP call will return debug information instead of doing the actual request

>>> posts.debug = True
>>> posts.get(userId=1)
{'endpoint': 'https://jsonplaceholder.typicode.com/posts',
 'params': {'userId': 1},
 'method': 'GET',
 'timeout': None}

Exceptions

  • As this package uses requests module to perform HTTP calls, so all exceptions will be raised by requests module itself.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].