ikod / dlang-requests

dlang http client library inspired by python-requests
Boost Software License 1.0
156 stars 32 forks source link

working smoothly with serialization #15

Open wilzbach opened 8 years ago

wilzbach commented 8 years ago

@JackStouffer correctly pointed out that Python's requests library should be a inspiration point (e.g. read the user testimonials for the reason).

One important feature is automatic serialization which is quite handy, so maybe we can keep this in mind that plugin a serializer / deserializer is an important use case.

wilzbach commented 8 years ago

@JackStouffer what other key features of request would you highlight?

JackStouffer commented 8 years ago

The key thing about requests (and it's also the thing I love about std.range and std.algorithm) is that the API is so simple that you can keep the day to day stuff in your head.

For example, I know without looking it up that the call to download the text of a page is

requests.get("url").text()

No protocol is simple, especially HTTP. But, there should be a simple high level with the ability to drop down into low level stuff, which is one of the key selling points of D.

ikod commented 8 years ago

@JackStouffer exactly, the simple, high level API is my goal - everyday things should be done in single simple API call.

This code is simple and do what you expect:

import requests;
import std.stdio;

void main() {
    writeln(getContent("http://dlang.org")); // write response body
    writeln(Request().get("http://dlang.org").responseBody); // same, in more verbose way
    writeln(Request().get("http://dlang.org").code); // write response code
}
yannick commented 8 years ago

its already fairly simple: https://github.com/yannick/requests-asdf-example/blob/master/source/app.d

string endpoint = "https://api.github.com/search/repositories?order=desc&sort=updated&q=language:D";

Item[] items = getContent(endpoint).to!string.parseJson["items"].deserialize!(Item[]);

it could be made even faster and nicer by allowing direct access to the buffer, see https://github.com/ikod/dlang-requests/issues/19