from twisted.internet import reactor from twisted.web.server import Request api = APIResource() site = Site(api, timeout=None) class FakeChannel(object): transport = None def make_request(method, path): req = Request(FakeChannel(), None) req.prepath = req.postpath = None req.method = method req.path = path resource = site.getChildWithDefault(path, req) return resource.render(req) reactor.listenTCP(8080, site) def get_callback(request): return 'GET callback' api.register('GET', '^/path/to/method', get_callback) def post_callback(request): return 'POST callback' api.register('POST', '^/path/to/method', post_callback) reactor.run()
deferred.addErrback(self.print_failure, request) return server.NOT_DONE_YET def _DELETE_single(self, request, id): @dbdefer def deleteTrack(session=None): Track = session.query(Track).filter(Track.id == id).first() session.delete(Track) return Track deferred = deleteTrack() deferred.addCallback(self.print_success_single, request) deferred.addErrback(self.print_failure, request) return server.NOT_DONE_YET apiresource = APIResource() Trackresource = TrackResource() staticresource = File('/var/lib/openshift/532f22855973cac4ef00044a/app-deployments/current/repo/static/www') apiresource.putChild('static', staticresource) apiresource.register('GET', '^/v1/Tracks/(?P<id>[^/]+)$', Trackresource._GET_single) apiresource.register('GET', '^/v1/Tracks', Trackresource._GET_list) apiresource.register('POST', '^/v1/Tracks', Trackresource._POST_create) apiresource.register('PUT', '^/v1/Tracks/(?P<id>[^/]+)$', Trackresource._PUT_update) apiresource.register('DELETE', '^/v1/Tracks/(?P<id>[^/]+)$', Trackresource._DELETE_single)
""" This module assembles the various API sub-modules into URL paths. These become the JSON API that external software can POST to for various things. """ import cgi from txrestapi.resource import APIResource from media_nommer.feederd.web.views import JobSubmitView """ URL assembly. """ API = APIResource() API.register('POST', '^/job/submit', JobSubmitView)