A rest client for easier life
Project description
pspring-rest-client
This framework is member of pspring based family of frameworks. It provides a means to create rest clients with minimal code. requests
library is used internally for http requests.
Annotations / Decorators that come along with this framework are listed below
-
@RestClient(url="")
This decorator will add few boiler plate code that is required to interact with any rest endpoint. The methods significant aresend
,getUrl
,addHeader
.The
send
method would accept all arguments thatrequests.request
method would. This method will throwPayloadException
for all not HTTP 200 responses. ThePayloadException
hasresponse
andstatusCode
attributes which can be further used for error handling. TheaddHeader(name,value)
method would add an header ThegetUrl
will get the url that is configured along with@RestClient
decorator. ThehandleError
method is exists on the object will be invoked when received a non http 200 response. -
@Mapping(method="",url="")
This decorator will take care of replacing parameters in the url from arguments passed, send the request and return the response
Useful classes in this framework
RegExResponseMapper
- this class can be used to tranform one dictionary to another using regex. An example is shown below. The source dictionary fields can be accessed using $
notation. In the below example message
is a field inside the `response dictionary.
regexmapper = RegExResponseMapper({
".*Customer does not exist.*" : {
"statusCode" : "404",
"code" : "APS-1001",
"message" : "$response.message"
},
".*" : {
"statusCode" : "500",
"code" : "APS-1002",
"message" : "$response.message"
}
})
@RestClient(url="https://myapi.com")
class MyRestClient():
@Mapping(method="GET",url="/user/{firstName}")
def getCustomer(self,firstName):
pass
def handleError(self,response):
return regexmapper.map(response)
To do:
- To return objects based on the return type from the response received.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pspring-rest-client-0.0.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78683e6e40542a1b1197b349d1b847fad31647566c698f740eb3866beba6b3b8 |
|
MD5 | 91eff6d1f9945998a94f2813d80affa9 |
|
BLAKE2b-256 | 706f42cd829ca13140d4534806425b65acaa7f7b3d145b408ea7494b08fa064f |
Hashes for pspring_rest_client-0.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b4938ccd378698ce0c43203a70dc59acb1c889afae04a9bfbec29348347ad2 |
|
MD5 | 118653551f63cc3feb27346a744717c0 |
|
BLAKE2b-256 | 178f838e9b1da82a39c7e5d724b77eea48890179ad95c58bc0be6aeb8ac26abc |