Giter Site home page Giter Site logo

Simple requests about cactoos-http HOT 22 OPEN

yegor256 avatar yegor256 commented on July 30, 2024
Simple requests

from cactoos-http.

Comments (22)

0crat avatar 0crat commented on July 30, 2024

@yegor256/z please, pay attention to this issue

from cactoos-http.

0crat avatar 0crat commented on July 30, 2024

@g4s8/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

from cactoos-http.

krzyk avatar krzyk commented on July 30, 2024

@llorllale I was actually looking how to do a request and it turns out I need to construct the http request using strings. Having something like here would make it much easier.

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@g4s8 I think we should recommend our users to use those request building objects from Takes Framework. Reimplementing them here would be silly, I think.

from cactoos-http.

krzyk avatar krzyk commented on July 30, 2024

@llorllale so this could be about extending the documentation (README.md) with example usage (replacing the JoinedText example with something less bare bones and more abstract).

from cactoos-http.

g4s8 avatar g4s8 commented on July 30, 2024

@yegor256 you meant that cactoos-http should depends on takes? I think it's not good, because it can be used not in web apps only or with other web-frameworks.

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@g4s8 no, it shouldn't depend on Takes. But, as @krzyk suggested, we should say in our README that: "if you need a more powerful instrument to build those HTTP requests, use Takes Framework, for example: ..."

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 why isn't Takes included in the list of competitors?

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@llorllale because it doesn't know how to make HTTP requests. It can only build them in text form.

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 I think you meant jcabi-http when you said:

I think we should recommend our users to use those request building objects from Takes Framework. Reimplementing them here would be silly, I think.

But I believe the design of jcabi-http is exactly what we're trying to avoid in cactoos-http.

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@llorllale I meant Takes, not jcabi-http

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@g4s8 @yegor256 @krzyk it would sound really weird for cactoos-http to direct users to another lib/framework just to fulfill this simple requirement (build http requests).

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256

we should recommend our users to use those request building objects from Takes Framework. Reimplementing them here would be silly,

I think then Takes should depend on cactoos-http

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@llorllale well, not a bad idea, but will require a lot of refactoring and class moving...

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 Takes has the option of just continuing doing their own thing.

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@g4s8 why did you leave out Wire in your proposal?

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 @g4s8 tell me what you think:

new HtResponse(
    new HtWire("host", port),
    new RqHeaders(
        new IterableOf<>(
            "Host: host:port",
            "Accept: */*"
        ),
        new RqBase(
            "GET", "/some/resource",
        )
    )
)

All requests would still be of type org.cactoos.Input.

With these decorators, we will basically be splicing and joining several Input or InputStream into a single one.

What we would need:

  • An equivalent for java's SequenceInputStream (org.cactoos.io.JoinedInput that implements Input)
  • SkipInput (I'm tempted to rename to something else)
  • The opposite of SkipInput

Thoughts
Insisting on keeping the Input abstraction on requests sure makes implementing decorators more difficult.

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@llorllale I like the code snippet above, but I didn't understand the text beneath. We already have everything that we need for this code. What else is needed and what is your question?

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 @g4s8

In my example above, we have two requests - RqBase and RqHeaders - and both are of type Input.

A Wire accepts only one Input in its method: Input send(Input request);.

Therefore we need to join all those requests/inputs into a single one and send it via the wire.

My question was if you guys accept this solution?

from cactoos-http.

yegor256 avatar yegor256 commented on July 30, 2024

@llorllale I didn't understand this:

In my example above, we have two requests - RqBase and RqHeaders - and both are of type Input.

RqBase (from Takes) is of time Request. I'm lost.

from cactoos-http.

llorllale avatar llorllale commented on July 30, 2024

@yegor256 the requirement is for providing "simple requests", not necessarily copy request objects from Takes.

Here is my example again with the Htr prefix to avoid confusion:

new HtResponse(
    new HtWire("host", port),
    new HtrHeaders(
        new IterableOf<>(
            "Host: host:port",
            "Accept: */*"
        ),
        new HtrBase(
            "GET", "/some/resource",
        )
    )
)

This Htr prefix is only valid for the purposes of this example, as I have yet to come up with a better prefix. (I think there would be too many naming conflicts if we use Ht for these)

from cactoos-http.

victornoel avatar victornoel commented on July 30, 2024

@g4s8 @llorllale @yegor256 for the record, there are such simple request objects already emerging in the test code base of cactoos-http, see #79. Just noting that here so that they are merged with whatever solution is found in this issue :)

from cactoos-http.

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.