Coder Social home page Coder Social logo

asphalt-web's People

Contributors

agronholm avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

asphalt-web's Issues

Open URL in browser

Would it make sense to have a configuration parameter that would open a browser window at a given URL based on the host URL, after the server has been launched? Something like:

component:
  type: fastapi
  components:
    myroot:
      type: dynamic:WebRootComponent
      open_url: my/url

Test client

It seems that a real server is used for testing. I was wondering if there could be a test client, similar to what Starlette has, and for instance a TestFastAPIComponent that would not start a server?

Broken links in documentation

Add l10n and i18n support

Thankfully, Babel now supports Python 3.4 and 3.5 starting from the recently released version 2.2.
I18n should take hints from request headers. It should also be settable in the session.

Pass lifespan to FastAPI application

FastAPI recently supported lifespan events, which are passed to the application like this:

from contextlib import asynccontextmanager

from fastapi import FastAPI


def fake_answer_to_everything_ml_model(x: float):
    return x * 42


ml_models = {}


@asynccontextmanager
async def lifespan(app: FastAPI):
    # Load the ML model
    ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
    yield
    # Clean up the ML models and release the resources
    ml_models.clear()


app = FastAPI(lifespan=lifespan)


@app.get("/predict")
async def predict(x: float):
    result = ml_models["answer_to_everything"](x)
    return {"result": result}

Does is mean that we cannot let the FastAPI component create the application object (since it's not possible to pass a lifespan), and that we must pass a ready-made application object?

Undefined WebSocket routes return 403 instead of 404

With asphalt-web, it looks like undefined WebSocket routes return a 403 rather than a 404:

from asphalt.core import Context
from asphalt.web.fastapi import FastAPIComponent
from fastapi import FastAPI
from websockets import connect

import pytest

@pytest.mark.asyncio
async def test(unused_tcp_port):
    application = FastAPI()

    async with Context() as ctx:
        await FastAPIComponent(
            components={},
            app=application,
            port=unused_tcp_port,
        ).start(ctx)

        async with connect(f"ws://127.0.0.1:{unused_tcp_port}/wrong_ws"):
            pass
        # websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.