Coder Social home page Coder Social logo

Routes with extension about sanic-routing HOT 4 CLOSED

sanic-org avatar sanic-org commented on June 22, 2024 1
Routes with extension

from sanic-routing.

Comments (4)

jacebrowning avatar jacebrowning commented on June 22, 2024 2

Perhaps something like this?

@app.get("/invoice/<invoice_id:uuid.ext:pdf|txt>")
async def invoice_handler(request, invoice_id, ext):
    ...

Using . as the separator could support all of these patterns:

/foo/<file.ext> # type is assumed to be 'file:str'
/foo/<file.ext:jpg>
/foo/<file.ext:jpg|png|gif|svg>
/foo/<file:uuid.ext>
/foo/<file:path.ext:jpg>
/foo/<file:int.ext:jpg|png|gif|svg>

Alternatively, if the file in <file:ext:png> also matched paths (/ character) then that would be sufficient for my use case.

from sanic-routing.

ahopkins avatar ahopkins commented on June 22, 2024 1

I have been looking at this one some more so we can finally wrap it up. The real challenge for me has been to determine what is the appropriate syntax here. While I can appreciate what @jacebrowning offered with file.ext, it really breaks a lot of other patterns and the entire concept that ext is itself the parameter "type".

Therefore, I offer this as the syntax:

/foo/<file:ext> # type is assumed to be 'file:str'
/foo/<file:ext=jpg>
/foo/<file:ext=jpg|png|gif|svg>
/foo/<file=uuid:ext>
/foo/<file=path:ext=jpg>
/foo/<file=int:ext=jpg|png|gif|svg>

from sanic-routing.

jacebrowning avatar jacebrowning commented on June 22, 2024

How would one specify the type of the file stem?

e.g. To ensure that invoice_id is a UUID and the extension is pdf or text.

from sanic-routing.

ahopkins avatar ahopkins commented on June 22, 2024

How would one specify the type of the file stem?

e.g. To ensure that invoice_id is a UUID and the extension is pdf or text.

🤔 Hmm.... that is not something I considered. This implementation would accept anything for the filename. It would be more equivalient to: /<foo>.pdf. Do you have any suggestions on what the implementation could look like?

from sanic-routing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.