31 lines
705 B
Python
31 lines
705 B
Python
#!/usr/bin/env python
|
|
|
|
import falcon
|
|
import json
|
|
|
|
|
|
XML = """<?xml version="1.0" encoding="utf-8"?>
|
|
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/4">
|
|
<cfdi:Emisor Rfc="SPE11071516A"/>
|
|
</cfdi:Comprobante>
|
|
"""
|
|
|
|
|
|
class JSONTranslator():
|
|
def process_response(self, req, resp, resource, req_succeeded):
|
|
if not hasattr(resp.context, 'result'):
|
|
return
|
|
resp.body = json.dumps(resp.context.result)
|
|
|
|
|
|
class AppApi(object):
|
|
|
|
def on_get(self, req, resp, rfc, cfdi):
|
|
resp.context['result'] = {'error': '', 'xml': XML}
|
|
resp.status = falcon.HTTP_200
|
|
|
|
|
|
app = falcon.App(middleware=[JSONTranslator()])
|
|
api = AppApi()
|
|
app.add_route('/api/{rfc}/{cfdi}', api)
|