GithubHelp home page GithubHelp logo

Comments (3)

Sammyjo20 avatar Sammyjo20 commented on July 18, 2024

Maybe this should be treated the new "first party" way of sending requests? It allows you to define default data in your constructor like an API token, without needing a keychain.

from saloon.

WalrusSoup avatar WalrusSoup commented on July 18, 2024

I think this is ok, but i don't think it's ultimately necessary.

I do see how this is getting a bit complicated, and in the end if kinda feels like code is being moved around and just shifted from place to place. After really, really thinking about it, i think the plugin approach is most straight forward and should probably just be titled as the official way to do authorization.

I made an example repo here of how it can be done. The only thing is that it needs a static helper. Given how class based Saloon is I believed that it was possible to keep the same 'cool' syntax approach, but after thinking about it, this solution is the most straight forward, has the least amount of code, and feels like the most compatible for everyone.

Having the token be able to be set on the request possibly felt like it was inconsistent since, typically, authorization headers are sent on all requests which made it feel more appropriate to be in the connector. But i can see a use case for both.

Maybe the final solution for this is just more documentation on the various approaches? But I think that settling on a "best practice is to put it in a plugin" will help portability a lot, then anyone using Saloon will know where authorization will be living without everyone doing their own approach.

I put an example repo here with a test located here

from saloon.

Sammyjo20 avatar Sammyjo20 commented on July 18, 2024

Hey, thanks for putting this together - that's super helpful so I appreciate it 🤘 I agree. I want to streamline how Saloon works to make it simpler to use. At the end of the day Saloon was born because configuring Guzzle caused a lot of thinking.

My main concern is that people will put something in the constructor of the connector and then when Saloon tries to boot up the connector, it fails because a specific argument is required. Currently this is worked around by doing the following:

Request::make()->setConnector(new MyConnector)->send();

I'm going to really think over how I'm going to handle authentication. I think I might change the wording from "keychain" to "credentials" or something a bit more descriptive, then if people choose to, they can create a Saloon Credential class that is just like you have in your example, however it's slightly simpler because people won't have to define their own plugin for it.

With all of this, the idea is that it is optional if people choose to.

from saloon.

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.