I want to separate my code with FastAPI.
My endpoint should receive a list of instance nodes and pass the list to NeoController.create_nodes
.
Old Code(Working):
from ontologies.neo import Node
from typing import List
db_instance = "Instance:Edge:Datastore:AbstractDatastore:Docker:MongoDB"
ds_instance = "Instance:Edge:DataSource:Camera:IDS"
instance = [
Node(db_instance, "MongoDB", attribute=['']),
Node(ds_instance, "IDS", attribute=[''])
]
NeoController.create_nodes(instance)
New Code:
from ontologies.neo import Node
from typing import List
db_instance = "Instance:Edge:Datastore:AbstractDatastore:Docker:MongoDB"
ds_instance = "Instance:Edge:DataSource:Camera:IDS"
instance = [
Node(db_instance, "MongoDB", attribute=['']),
Node(ds_instance, "IDS", attribute=[''])
]
request = requests.post('http://127.0.0.1:8080/create/?instance=instance') #how to format the URL the right way?
API-Code:
from ontologies.neo import Node
from fastapi import FastAPI, Query
from typing import List
app=FastAPI(
title="Neo4jAPI",
)
@app.post("/create/")
def post(instance: List[Node] = Query(None)): #How to fix the Header, i am getting a Assertation Error
NeoController.create_nodes(instance)
return JSONResponse(instance)
Questions:
- How to fix the URL-Request?
- How to fix the API-Header?
I read some other questions/posts and code examples, but wasn't able to fix it.