Comments (3)
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.
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.
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)
- Rate Limit Plugin: Issue with 'allow(1)->everySeconds(1)->sleep()' Exceeding One Request per Second
- Inteliphense cannot recognize the merge() method on request HOT 3
- Connector default headers overwrite request body headers
- Remove authentication on a specific request HOT 5
- Some properties are removed from the response body
- Using non-standard HTTP methods HOT 2
- Generating Documentation Files for GPT on ChatGPT HOT 4
- Tests using Fixtures with custom Authenticators record incorrect response HOT 1
- async request with multi connector HOT 1
- Allow partial overriding of fixtures HOT 2
- Asserting a request is sent by closure parameter HOT 1
- Connector object() throws an exception but json returns null|object? HOT 1
- Feature Request: Requests have the ability to return a Colleciton HOT 1
- Connector does not support `defaultBody()`? HOT 3
- Request class cannot accept `$query` property in constructor HOT 3
- Possible to Use Multiple Instances of Same Request in Single Test?
- Override Connector defaultHeaders() in request HOT 5
- Offloading a Listener for SentSaloonRequest events to a queue returns error HOT 3
- Pagination: `currentPage` doesn't align with `page` HOT 2
- Additional requests with the main request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from saloon.