What is it?
============
a python jsend module.
compatable with jsend: http://labs.omniti.com/labs/jsend
Shortely: (borrowed from http://labs.omniti.com/labs/jsend)
=================================================================
"""
A basic JSend-compliant response is as simple as this:
{{{
{
status : "success",
data : {
"post" : { "id" : 1, "title" : "A blog post", "body" : "Some useful content" }
}
}
}}}
When setting up a JSON API, you'll have all kinds of different types of calls and responses. JSend separates responses into some basic types, and defines required and optional keys for each type:
||''Type''||''Description''||''Required Keys''||''Optional Keys''||
||success ||All went well, and (usually) some data was returned.||status, data||||
||fail ||There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied||status, data||||
||error ||An error occurred in processing the request, i.e. an exception was thrown||status, message||code, data||
"""
This module includes 3 classes:
==============================
RSuccess --> Result Success
RFail --> Result Fail
RError --> Result Error
Usage: (sample)
========================
In [1]: from jsend import RSuccess, RFail, RError # from jsend import *
In [2]: rs = RSuccess()
In [3]: rs
Out[3]: {'data': {}, 'status': 'success'}
In [4]: rs.data['post'] = {'username' : 'you', 'password' : 'pwd' }
In [5]: rs
Out[5]: {'data': {'post': {'password': 'pwd', 'username': 'you'}}, 'status': 'success'}
In [6]: rf = RFail()
In [7]: rf
Out[7]: {'data': {}, 'status': 'fail'}
In [8]: rf.data['why'] = 'You have entered the wrong number'
In [9]: rf
Out[9]: {'data': {'why': 'You have entered the wrong number'}, 'status': 'fail'}
In [10]: rr = RError
In [11]: rr
Out[11]: jsend.jsend.RError
In [12]: rr = RError()
In [13]: rr
Out[13]:
{'code': {},
'data': {},
'message': 'error occurres during processing',
'status': 'error'}
In [14]: rr.data['stack'] = 'stack overflows'
In [15]: rr.code['return_code'] = 1
In [16]: rr
Out[16]:
{'code': {'return_code': 1},
'data': {'stack': 'stack overflows'},
'message': 'error occurres during processing',
'status': 'error'}
============
a python jsend module.
compatable with jsend: http://labs.omniti.com/labs/jsend
Shortely: (borrowed from http://labs.omniti.com/labs/jsend)
=================================================================
"""
A basic JSend-compliant response is as simple as this:
{{{
{
status : "success",
data : {
"post" : { "id" : 1, "title" : "A blog post", "body" : "Some useful content" }
}
}
}}}
When setting up a JSON API, you'll have all kinds of different types of calls and responses. JSend separates responses into some basic types, and defines required and optional keys for each type:
||''Type''||''Description''||''Required Keys''||''Optional Keys''||
||success ||All went well, and (usually) some data was returned.||status, data||||
||fail ||There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied||status, data||||
||error ||An error occurred in processing the request, i.e. an exception was thrown||status, message||code, data||
"""
This module includes 3 classes:
==============================
RSuccess --> Result Success
RFail --> Result Fail
RError --> Result Error
Usage: (sample)
========================
In [1]: from jsend import RSuccess, RFail, RError # from jsend import *
In [2]: rs = RSuccess()
In [3]: rs
Out[3]: {'data': {}, 'status': 'success'}
In [4]: rs.data['post'] = {'username' : 'you', 'password' : 'pwd' }
In [5]: rs
Out[5]: {'data': {'post': {'password': 'pwd', 'username': 'you'}}, 'status': 'success'}
In [6]: rf = RFail()
In [7]: rf
Out[7]: {'data': {}, 'status': 'fail'}
In [8]: rf.data['why'] = 'You have entered the wrong number'
In [9]: rf
Out[9]: {'data': {'why': 'You have entered the wrong number'}, 'status': 'fail'}
In [10]: rr = RError
In [11]: rr
Out[11]: jsend.jsend.RError
In [12]: rr = RError()
In [13]: rr
Out[13]:
{'code': {},
'data': {},
'message': 'error occurres during processing',
'status': 'error'}
In [14]: rr.data['stack'] = 'stack overflows'
In [15]: rr.code['return_code'] = 1
In [16]: rr
Out[16]:
{'code': {'return_code': 1},
'data': {'stack': 'stack overflows'},
'message': 'error occurres during processing',
'status': 'error'}
Metadata
Release files for python-jsend 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_jsend_0.17.tar.gz | 6.7 kB | Details |
Release files / python_jsend_0.17.tar.gz
| Download URL | python_jsend_0.17.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0b47d38da4fd6ee13dd9333511e9f6c35ee682ecf71819fa2bec39d0cf2e1ce
|
|
BLAKE2b-256 checksum How to use checksums |
c81ff4f001ca23e81d6d961a33c79fbeba9c11b53428aea58f2090d0ccd53e30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |