Hello All I am new to rest api and trying to write a get endpoint to which user send a query parameter say FieldSet. Based on values in FieldSet I want to return response. For Example : Endpoint : @app.get(/blogs/) Blogs endpoint has say 100 fields. But user want to control which fields he/she may need in response. User will hit URL as /blogs/?fieldSet=blogID,blogCreator.
So response only should contain two feilds.
Options
- Is it possible with FastAPI's pyndantic response schema ? Can schema be created dynamically based on query parameter values ?
- Should I create a a sql based on fieldSet values at runtime and create a response ?
- if second option holds true , can we use SqlAlchemy or should I write raw SQLs against DB ?
- Also, How to create nested json if one blog may have one or more creators ?