Comments (3)
by design, the promises must return http responses. this is not a generic promises library but a custom interface for httplug. it is an excellent idea to have your library/application not use http objects to carry information. but rather than building into the httplug library, you should write an adapter type class that internally uses httplug and exposes domain objects to the rest of your code. if you need promises in your code, use a generic promises library and wrap the httplug promise in that promise.
does this make sense? or am i misunderstanding the issue?
from httplug.
Hi @aferrandini
Thanks for reaching out. May I ask why would you like to use promises like that?
By design promises inside the plugin chain (and during the request lifecycle) should not accept or return any other values than ResponseInterface/HttplugException. This is because we have to keep the HttpAsyncClient contract which states the returned Promise will resolve to one of the above.
Since you need to return an object anyway (not log the response for example, which does not require the response to be there at a specific time, but somewhere in the future), you lose the advantage of an async request, since you need to synchronize at some point.
You can still use async though, but you have to wait for the promise resolution, and then you can do the deserialization.
If you want to see an example how we handle deserialization, take a look at https://github.com/FriendsOfApi/boilerplate
Although this is a limitation of some kind, it allows us to provide a consistent contract. If you absolutely need this inside a plugin, you can try wrapping the returned promise into a custom one, invoke the success and failure handlers of the original one, and do whatever you want from that point.
from httplug.
First of all, thanks for your quickly responses.
In our case, we have an abstract client that handles both sync/async requests. In fact, the request always is async, but the abstract client waits for the promise to convert this call to sync.
Using the promise this way, the specific-domain client is using the onfullfilled promis parameter to deserialize the object from the response body at this point or returning the promise with the anonymous function which deserialize the body.
We will try to wrap the promise with a custom promise to handle specific domain objects and create a custom contrat for our code :)
Thanks
from httplug.
Related Issues (20)
- Circuit Breaker HOT 6
- Missing badges HOT 2
- Sending file from a multipart stream HOT 13
- Add support for HTTP proxies and SSL Client certificates? HOT 7
- How to set timeout for a request while being abstracted from a HttpClient implementation? HOT 6
- Implementation Question: how to code Client options in a library-agnostic way? HOT 5
- Benchmarks? HOT 2
- Prepare version 2.0 HOT 6
- HMAC Authentication Plugin HOT 4
- phpstan complains about Http\Client\Exception HOT 6
- Adding deprecated HOT 5
- HttpException create method self vs static HOT 1
- Symfony HTTP Client Adapter HOT 1
- PSR-18: Network / Request exception inheritance HOT 1
- Add psr-18 github tag HOT 1
- Throwable not supported HOT 8
- State of async HTTP clients and promises HOT 13
- PHP 8.0 support HOT 1
- "php-http/httplug" package is not installed HOT 7
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 httplug.