def serve_schema_js(schema: APISchema, templates: Templates) -> http.Response: codec = CoreJSONCodec() base64_schema = base64.b64encode(codec.encode(schema)).decode('latin1') template = templates.get_template('apistar/schema.js') content = template.render(base64_schema=base64_schema) headers = {'Content-Type': 'application/javascript'} return http.Response(content, headers=headers)
def mockreturn(self, request): codec = CoreJSONCodec() body = force_text(request.body) content = codec.encode(Document(content={'data': json.loads(body)})) return MockResponse(content)
def serve_schema(schema: APISchema) -> http.Response: codec = CoreJSONCodec() content = codec.encode(schema) headers = {'Content-Type': codec.media_type} return http.Response(content, headers=headers)