Support string formatting with `uplink.Header` annotation
Dynamic HTTP Header fields are declared using the uplink.Header annotation:
@get("/user")
def get_user(self, authorization: Header):
"""Get an authenticated user."""
Adding support for string formatting could simplify the method's call and further abstract the HTTP:
@get("/user")
def get_user(self, authorization: Header(pattern="Basic {}")):
"""Get an authenticated user."""
@prkumar I've started working on this, headers will now accept a string as argument.
I want to check with you as to how to tackle in case of a list. Should I bother with checking if the first item in the list ends with a :? In case someone passes a list with:
["Accept:", "application/vnd.github.v3.full+json"]
Honestly I don't think anyone would pass the colon in the first argument, but a bad copy-paste might brake things up so I'm trying to account for it. Let me know what you think 👍
Another idea is to have Argument Annotations accept callbacks to transform the given argument value:
Header(callback="Basic {}".format). This would offer a lot more functionality.