Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

CORS support for bareasgi

Project description


CORS support for bareASGI (read the documentation)


A convenience function is provided.

import json
import logging
import uvicorn
from bareasgi import (
from bareasgi_cors import CORSMiddleware


async def get_info(scope, info, matches, content):
    text = json.dumps(info)
    return 200, [(b'content-type', b'application/json')], text_writer(text)

async def set_info(scope, info, matches, content):
    text = await text_reader(content)
    data = json.loads(text)
    return 204, None, None

cors_middleware = CORSMiddleware()

app = Application(info={'name': 'Michael Caine'}, middlewares=[cors_middleware])

app.http_router.add({'GET'}, '/info', get_info)
app.http_router.add({'POST', 'OPTIONS'}, '/info', set_info), port=9010)

The POST method

In the above example an OPTION method is included with the POST. This is always required with a POST as a browser will try first with an OPTION.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bareasgi-cors, version 3.1.1
Filename, size File type Python version Upload date Hashes
Filename, size bareasgi_cors-3.1.1-py3-none-any.whl (8.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bareasgi-cors-3.1.1.tar.gz (8.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page