infrae/infrae.rest
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
master
Could not load branches
Nothing to show
Could not load tags
Nothing to show
{{ refName }}
default
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
-
Clone
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more.
- Open with GitHub Desktop
- Download ZIP
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
=========== infrae.rest =========== ``infrae.rest`` provide a simple way to write REST APIs in Zope 2. API === REST component -------------- ``infrae.rest`` provides mainly a base class ``REST`` which behave a lot like a Grok view:: from infrae.rest import REST class MyAction(REST): """My action REST API. """ def POST(self, name, value): # Called by POST /content/++rest++myaction&name=foo?value=bar return 'Success' def GET(self): # Called by GET /content/++rest++myaction values = self.context.something() return self.json_response(values) You just have to grok your package to make it available. - You can provide: ``POST``, ``GET``, ``HEAD``, ``DELETE`` requests. - You can use the directives ``grok.name``, ``grok.require`` and ``grok.context`` to configure your REST API. They work exactly like on a ``grok.View``. - If you need, you can manually query a REST component with the help of ``infrae.rest.queryRESTComponent``. Nesting REST component ---------------------- You can nest REST component. In that you should use the grok directive adapts in order to define which is the parent handler, and the context:: from infrae.rest import REST from five import grok from OFS.Folder import Folder class ParentHandler(REST): grok.context(Folder) def GET(self): # Called by GET /folder/++rest++parenthandler return u'Hello' class ChildHandler(REST): grok.adapts(ParentHandler, Folder) def GET(self): # Called by GET /folder/++rest++parenthandler/childhandler return u'Child RESTWithTemplate component -------------------------- You can alternatively use the base class ``RESTWithTemplate``. The only difference is that your class will be associated to a Grok template automatically. Repository ========== Sources can be found in Git at: https://github.com/infrae/infrae.rest
About
Define a REST API to access and manage Zope 2 content
Resources
Stars
Watchers
Forks
Packages 0
No packages published