-
Notifications
You must be signed in to change notification settings - Fork 31
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
Alternative flexible request API #98
Comments
Hello Jan!
Thanks for your idea! I'll see how this can be done. I'm thinking about
arguments type safety and it would be definitely nice to implement. It is
easy and I will do it.
Related to the other proposals I have to look closely what can I do.
Thanks!
чт, 28 мар. 2019 г., 14:58 Jan Jurzitza [email protected]:
… I would like to suggest a generic high-level API that could be used for
requests instead of getContent/postContent:
Response request(Args...)(HTTPMethod method, URL url, Args args);
basically it should allow any kind of request manipulating parameter and
incoperate it into the request.
So for example to set headers, query string, form data and cookies in a
high level request:
MultipartForm form;
form.add(formData("file", File("test.bin", "rb"), ["filename":"test.txt", "Content-Type": "application/octet-stream"]));
request(HTTPMethod.POST, URL("https://example.org/upload"),
httpHeader("Authorization", "Basic 123"),
queryParams("name", "any name", "age", 42),
form,
Cookies([Cookie("/", null, "sessionId", "abc")])
);
I used URL here to make it more typesafe so you don't accidentally pass
other data as URL. (it exists in vibe and could be added as light wrapper
here too)
Basically it should accept any arguments which could manipulate the
request and apply them all on the request. If basic wrappers around simple
values are used this is extensible, readable, typesafe and emulates named
arguments with it. It would be cool if Json body would also be supported
using JSONValue or vibe.d json here.
It should also handle redirects transparently. (not sure how well this
would integrate with still allowing the user to read the response using
ranges)
The response object should probably get an additional utility function
converting the response to a string (instead of bytes), but all the other
stuff should exist and be accessible. It could also contain helper
functions to parse the content as Json or JSONValue.
It would be a fairly high-level function that still has optional access to
a lot of the low level stuff, which I think would be very useful.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#98>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABNuScWMz75Flz6fcqHTZT-xCGT274wRks5vbLyIgaJpZM4cQGKk>
.
|
Hello @WebFreak001 It would be nice to be able to write high level API calls in pythonic way: MultipartForm form;
form.add(formData("file", File("test.bin", "rb"), ["filename":"test.txt", "Content-Type": "application/octet-stream"]));
auto content = request(method=HTTPMethod.POST, url=URL("https://example.org/upload"),
headers=["Authorization": "Basic 123"],
params = queryParams("name", "any name", "age", 42),
form = form,
cookies = Cookies([Cookie("/", null, "sessionId", "abc")])
); where each parameter can take any position and is optional. I'll play and see what is the best way to implement this. |
Any update on this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to suggest a generic high-level API that could be used for requests instead of getContent/postContent:
basically it should allow any kind of request manipulating parameter and incoperate it into the request.
So for example to set headers, query string, form data and cookies in a high level request:
I used URL here to make it more typesafe so you don't accidentally pass other data as URL. (it exists in vibe and could be added as light wrapper here too)
Basically it should accept any arguments which could manipulate the request and apply them all on the request. If basic wrappers around simple values are used this is extensible, readable, typesafe and emulates named arguments with it. It would be cool if Json body would also be supported using JSONValue or vibe.d json here.
It should also handle redirects transparently. (not sure how well this would integrate with still allowing the user to read the response using ranges)
The response object should probably get an additional utility function converting the response to a string (instead of bytes), but all the other stuff should exist and be accessible. It could also contain helper functions to parse the content as Json or JSONValue.
It would be a fairly high-level function that still has optional access to a lot of the low level stuff, which I think would be very useful.
The text was updated successfully, but these errors were encountered: