Giter Club home page Giter Club logo

Comments (2)

redodo avatar redodo commented on June 28, 2024

Do you have a specific need to use your actual implementation,
instead of simply concatenating path segments ?

Yes.

The wraps in my implementation are programmed to overload settings
from their parents. So, when a request is executed, the information
will flow from top to bottom. Every wrap can add their default config
if it's not there.

Now, this could also be implemented by going from bottom to top.
However, wraps are made to be saved for later use. This means that a
bottom to top solution could behave weirdly. For example:

example = tortilla.wrap('https://api.example.org')

# worst case scenario of endpoint
users = example('get').users('for', 'each', params={'this': 'that'})

# we've logged in and set the authorization header
example.headers.authorization = 'secret key'

# this won't send the authorization header because the `example` parent
# can't modify the request information
users.get('someone')

If we use a top to bottom method, the request will fall through our
example wrap which can add the headers and other config.

URLs are created seperately from the request in the url() method.
This method concatenates URL parts from top to bottom and could be
done in the request method. But, because the __repr__ method also
uses the URL, I chose to abstract the URL creation in a different
function to keep things DRY.

I'm completely open to modifications to improve performance, but I
don't want it to impact the flexibility of using the library. :)

from tortilla.

JulienPalard avatar JulienPalard commented on June 28, 2024

OK I understand better your point of view, my basic implementation clearly can't handle this, but I never though about storing intermediates values, nor modifing them and expecting it to still work ;-)

from tortilla.

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.