I'm trying to create an API using FastAPI + MongoDB that can return multiple values from the request. The MongoDB is full of data and using mongoengine I can consult one or all data when sending a request to the specific endpoint. What I'm trying to do now is receive one or more data from an endpoint, for example:
When consulting the endpoint http://127.0.0.1:8000/rice
I get a JSON response with all the data from this item that is on MongoDB. But the problem is that I need to have this endpoint consulting one or more data from MongoDB and return as much data as the user sends to the endpoint, for example: http://127.0.0.1:8000/rice&pasta&bean
and return the JSON with the information that it is in the MongoDB about rice
, pasta
and bean
.
In the code I have a main.py with the routes like:
@app.get('/{description}', status_code=200)
def get_description(description):
return JSONResponse(TabelaService().get_description(description))
This function calls another function that call another function that use queryset
to consult the data from MongoDB and serialize it:
def get_description(self, description):
try:
description = TabelaNutricional.get_by_description(description)
return self.serialize(description)
except:
raise DescriptionNotFound
And bellow is the function who get the data from MongoDB:
@queryset_manager
def get_by_description(doc_cls, queryset, description):
nutriente = queryset(description=str(description)).get()
return nutriente
Does anyone has a clue to how to get more data in the endpoint? Thank you!