rest-http-client: Configurable and flexible http(s)-client for your python applications
Description
The rest-http-client package is a basic configurable rest api client. This package is currently tested on Python =< 2.7. This package worked on multithreding mode
Installation
pip install rest-http-client
or
download the latest release and run
python setup.py install
Usage
Example in folder tests.
The first you can configure http or https client
import logging
from rest_api_client import HttpClient
from .testapis import TestAPIs
logger = logging.getLogger('http_logger')
class TestRestAPI(HttpClient):
_WRAPPERS = [ # list of api clients
TestAPIs
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.testapis = None
for e in self._WRAPPERS:
attr_name = e.__name__.lower()
setattr(self, attr_name, e(self))
class TestAPIs where you list all api requests
from http import HTTPStatus
class TestAPIs:
def __init__(self, client):
self.client = client
self.client.add_headers({
"Accept": "*/*",
"Content-Type": "application/json",
})
def get_request(self):
response = self.client.get('/echo')
assert response.status_code == HTTPStatus.OK, 'Invalid request'
return response
def post_request(self, body: dict):
response = self.client.post('/echo/post/form', json=body)
assert response.status_code == HTTPStatus.OK, 'Invalid request'
return response
Then has to create object of TestRestAPI and use in tests
from tests.api import TestRestAPI
client = TestRestAPI(address='https://reqbin.com')
def test_check_get_request():
response = client.testapis.get_request()
assert 'Simple echo interface for HTTP methods' in response.text, 'Something is wrong'
def test_check_post_request():
body = {
'key1': 'value1',
'key2': 'value2',
}
response = client.testapis.post_request(body=body)
assert 'Success' in response.text, 'Something is wrong'
Console Output
============================= test session starts =============================
collecting ... collected 2 items
test_apis.py::test_check_get_request
test_apis.py::test_check_post_request
======================== 2 passed, 3 warnings in 0.75s ========================
Process finished with exit code 0
PASSED [ 50%]
PASSED [100%]
Metadata
Release files for rest-http-client 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rest-http-client-0.8.tar.gz | 4.7 kB | Without provenance | Details for rest-http-client-0.8.tar.gz |
Release files / rest-http-client-0.8.tar.gz
| Download URL | rest-http-client-0.8.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1d83b21a2fa4ea61939f77bd4e38399426b58a86e68647ad96c5684ff64af76
|
|
BLAKE2b-256 checksum How to use checksums |
d02a7230a8686bb4e98fb5f94446cf805cf216f0ab5a6f90ac6401c3d8b5a3ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
|
Security for rest-http-client 0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.