Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request syntax in flama #41

Closed
sugizo opened this issue Feb 3, 2021 · 1 comment
Closed

request syntax in flama #41

sugizo opened this issue Feb 3, 2021 · 1 comment

Comments

@sugizo
Copy link

sugizo commented Feb 3, 2021

objective
can have api from cli
e.g.
request.headers['api_key']
curl -X GET -i http://localhost:8000/api/http_api_key/instrument/ -H 'api_key: stifix'
request.query_params
curl -X PUT -i "http://localhost:8000/api/put/instrument/2?name=name0&strings=0"
request.form()
curl -X PUT -d "name=name1&strings=1" -i http://localhost:8000/api/put/instrument/2
request.json()
curl -X PUT -d '{"name": "name2", "strings": 2}' -i http://localhost:8000/api/put_json/instrument/2

in starlette we can use request
e.g.

def test(request):
    request.headers['api_key']
    request.query_params
    request.form()
    request.json()

since flama is base on starlette, what is equivalent of starlette request above ?

thanks

@perdy
Copy link
Collaborator

perdy commented Mar 17, 2021

You can just inject the dependency into the function:

from flama.http import Request


def test(request: Request):
    request.headers["api_key"]
    request.query_params
    request.form()
    request.json()

@sugizo sugizo closed this as completed Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants