dlang-requests
dlang-requests copied to clipboard
working smoothly with serialization
@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.
- https://github.com/s-ludwig/std_data_json (json serialization from vibed, proposed to be the new standard lib)
- https://github.com/jacob-carlborg/orange (multiple output formats)
- https://github.com/tamediadigital/asdf (optimized for speed)
@JackStouffer what other key features of request would you highlight?
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.
@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
}
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