Setup.
1. virtualenv myapp
2. pip install git+https://github.com/vahana/prf
3. pcreate -s starter myapp
4. cd myapp
5. pip install -e .
Run.
pserve development.ini
This will run a server and you can navigate your browser to http://0.0.0.0:6543
Adding prf resources.
In the __init__.main function of your pyramid app declare your resources:
def main():
...
config.include('prf')
root = config.get_root_resource()
user = root.add('user', view='prf.view.NoOp')
user_story = user.add('story', 'stories', view='prf.view.NoOp')
...
The following endpoints are declared with the code above:
/users/{id}
/users/{user_id}/stories/{id}
You can now navigate to http://0.0.0.0:6543/users or http://0.0.0.0:6543/users/1/stories
'NoOp' view as name suggests does not do much. You will need to create your own views for each resource.
In our case UsersView and UserStoriesView.
UsersView could look something like this:
from prf.view import BaseView
Users = [
{
'id': 0,
'name':'Alice',
},
{
'id': 1,
'name':'Bob',
},
{
'id': 2,
'name':'Katy',
},
]
class UsersView(BaseView):
def index(self):
return Users
def show(self, id):
return Users[int(id)]
def create(self):
Users.update(**self._params)
def delete(self, id):
del Users[id]
You need to change the view for the users resource to point to this class:
user = root.add('user', view=UsersView)
Restart the server and navigate to http://0.0.0.0:6543/users
Above we declared `index`, `show`, `create` and `delete` actions which correspond to: GET collection, GET resource, POST resource and DELETE resource respectively. You could also declare `update`, which would correspond to the PUT method. You dont need to declare all of them, only those you need. The missing ones will automatically return 405 Method Not Allowed error.
Comment out the `index` action and try.
Happy RESTing !
0.0
---
- Initial version
Metadata
Release files for prf 0.0.22
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 | |
|---|---|---|---|---|
| prf-0.0.22.tar.gz | 44.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prf-0.0.22-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 101.5 kB
Release files / prf-0.0.22.tar.gz
| Download URL | prf-0.0.22.tar.gz |
|---|---|
| Size | 44.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0ea291799613def308a8a33231a83934a0326576c11404c603ea86bbc7ce0e7
|
|
BLAKE2b-256 checksum How to use checksums |
462638f280cb24c76039647fd064800fea5c1b90c2fec9b2455d56949a1f6413
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / prf-0.0.22-py2-none-any.whl
| Download URL | prf-0.0.22-py2-none-any.whl |
|---|---|
| Size | 57.4 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
d81a2c4e57497706077c399afec51d9b6050bec3851c0c257fe2eafb98ab4a00
|
|
BLAKE2b-256 checksum How to use checksums |
ff282f417b3ca9da4c2f2abf525f85b8362584a2595b532d18611771b09225d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for prf 0.0.22
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.