8000 GitHub - Rekoc/cassandra-fastapi
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rekoc/cassandra-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cassandra-fastapi

A example of microservicemade with FastAPI (0.63+) for Apache Cassandra (3.0+) and DataStax python-driver secured with API keys check.

The driver supports Python 3.7 and 3.8+.

Installation

Fist you must git clone this repository:

$ git clone https://github.com/Rekoc/cassandra-fastapi.git

Then installation through pip and virtual-env is recommended:

$ cd cassandra-fastapi
$ pip install -r requirements.txt

You must have installed Apache Cassandra (3.0+) on your cloud/desktop. Finally, lunch the FastAPI app:

$ uvicorn main:app --reload

All good !

Requests

Check http://127.0.0.1:8000/docs in your web browser.

How-to adapt the code ?

  1. Create your own model(s) in models.exemple, check https://fastapi.tiangolo.com/ for more informations
  2. Update the request's model
@app.post("/model/{table}")
async def post_model(table: str, item: MyModel,
                     api_key: APIKey = Depends(get_api_key)):
    returned_value = session.execute(
        "INSERT INTO {} (id, value) VALUES ({}, {});".format(table, item.id, item.value)
    )
    return JSONResponse(
        {'detail': "model has been added"},
        status_code=status.HTTP_200_OK
    )

becomes

@app.post("/model/{table}")
async def post_model(table: str, item: MyOwnModelMadeForMyApp,
                     api_key: APIKey = Depends(get_api_key)):
    returned_value = session.execute(
        "INSERT INTO {} (field_id, field_value, new_field) VALUES ({}, {}, {});".format(table, item.field_id, item.field_value, item.new_field, ...)
    )
    return JSONResponse(
        {'detail': "model has been added"},
        status_code=status.HTTP_200_OK
    )

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0