Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working smoothly with serialization #15

Open
wilzbach opened this issue May 25, 2016 · 4 comments
Open

working smoothly with serialization #15

wilzbach opened this issue May 25, 2016 · 4 comments

Comments

@wilzbach
Copy link

@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
Copy link
Author

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

@JackStouffer
Copy link

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
Copy link
Owner

ikod commented May 26, 2016

@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
Copy link

yannick commented Jun 8, 2016

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
#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants