uplink icon indicating copy to clipboard operation
uplink copied to clipboard

Support string formatting with `uplink.Header` annotation

Open prkumar opened this issue 8 years ago • 2 comments

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 avatar Dec 19 '17 19:12 prkumar

@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 👍

FabioRosado avatar Dec 30 '17 19:12 FabioRosado

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.

prkumar avatar Oct 19 '18 16:10 prkumar