cactoos-http icon indicating copy to clipboard operation
cactoos-http copied to clipboard

Simple requests

Open g4s8 opened this issue 7 years ago • 22 comments

I think there should be some simple request objects, like:

new HtResponse(
  new RqSimple("GET", "https://foo.bar?param=1")
);
// or
new HtResponse(
  new RqSimple.Get("https://foo.bar?param=1")
);

g4s8 avatar Apr 04 '18 19:04 g4s8

@yegor256/z please, pay attention to this issue

0crat avatar Apr 04 '18 19:04 0crat

@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!

0crat avatar Apr 04 '18 19:04 0crat

@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.

krzyk avatar May 09 '18 12:05 krzyk

@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.

yegor256 avatar May 10 '18 06:05 yegor256

@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).

krzyk avatar May 10 '18 08:05 krzyk

@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.

g4s8 avatar May 10 '18 08:05 g4s8

@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: ..."

yegor256 avatar May 10 '18 11:05 yegor256

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

llorllale avatar May 15 '18 14:05 llorllale

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

yegor256 avatar May 19 '18 14:05 yegor256

@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.

llorllale avatar May 21 '18 15:05 llorllale

@llorllale I meant Takes, not jcabi-http

yegor256 avatar May 21 '18 16:05 yegor256

@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).

llorllale avatar May 22 '18 14:05 llorllale

@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

llorllale avatar Jun 06 '18 18:06 llorllale

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

yegor256 avatar Jun 12 '18 17:06 yegor256

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

llorllale avatar Jun 14 '18 12:06 llorllale

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

llorllale avatar Jun 14 '18 12:06 llorllale

@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.

llorllale avatar Jun 29 '18 14:06 llorllale

@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?

yegor256 avatar Jul 03 '18 08:07 yegor256

@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?

llorllale avatar Jul 03 '18 15:07 llorllale

@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.

yegor256 avatar Jul 18 '18 06:07 yegor256

@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)

llorllale avatar Jul 21 '18 19:07 llorllale

@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 :)

victornoel avatar Apr 14 '19 14:04 victornoel