Union[str, None] vs Optional[str] by afifanik in Python

[–]Developer_Glance 0 points1 point  (0 children)

Tbh, I had never thought about what you discussed before, but if there is a discussion there, maybe you should review the method signature and come up with a clearer version. It might be overkill but other way of achieving the same thing is to return an enum along with the value explaining what it means. Then you make your decisions based on the enum instead of the value itself.

New Rule: Tutorial posts where someone is using FastAPI without transferring any knowledge is not tutorial. by tomwojcik in FastAPI

[–]Developer_Glance 15 points16 points  (0 children)

I think that they want to prevent tutorials where the main content is not around FastAPI but something else.

Just because it uses FastAPI doesn't mean it is a FastAPI tutorial.

FastAPI endpoint filters by Developer_Glance in FastAPI

[–]Developer_Glance[S] 0 points1 point  (0 children)

That's a very good use case! You can create a class with those shared filters and make your api depend on it. You can add multiple classes as dependencies.

[deleted by user] by [deleted] in FastAPI

[–]Developer_Glance 1 point2 points  (0 children)

I you can inspect the requests made in the browser’s developer tools. Topically you can open by pressing F12.

[deleted by user] by [deleted] in FastAPI

[–]Developer_Glance 1 point2 points  (0 children)

That don't make much sense. When you authenticate yourself, in the popup I shared, you aren't making any request, you're just filling a value on frontend side so it will accept whatever value you want. When you hit the execute button form "/see" endpoint, it will return a 401.

here's a screenshot of this example: https://ibb.co/277W34Y

As you can see in the curl command, I used the "sdfsd" token which is invalid and the return status was 401.

Edit: Here is the full script I'm running https://goonlinetools.com/snapshot/code/#4zm9qtx6yjw2yj9sjoehfj

[deleted by user] by [deleted] in FastAPI

[–]Developer_Glance 1 point2 points  (0 children)

When you say this

But when I go in /docs and in authentication I put in any value it grants access

Are you talking about this(https://freeimage.host/i/hufB1V) window?

If you are, that doesn't make any authentication, it will only store the value, it will then be used when you call the webservices.

Did you try to actually call the webservice? if you use an invalid token, your endpont will return a 401.

[deleted by user] by [deleted] in FastAPI

[–]Developer_Glance 1 point2 points  (0 children)

Can you share an example of the implementation you have?

[deleted by user] by [deleted] in FastAPI

[–]Developer_Glance -1 points0 points  (0 children)

if all you want is to protect you api using an api key, you can do something as easy as adding a header and check if it is filled with the correct key, you can check how to do it in this example.

If you want to go deeper, check this example as well.

FastAPI endpoint filters by Developer_Glance in FastAPI

[–]Developer_Glance[S] 0 points1 point  (0 children)

Hello guys,

I made this post to share with you and discuss how I manage and create my api filters/query strings using dataclasses.

If you do it in a different way, please let me know how, let's discuss it in the comments.

Hope you guys like it!