digitalmars.D.learn - Can't understand how to do server response with vibed
- Suliman (15/15) Nov 28 2015 Could anybody help me to understand how to complete HTTP response
- Suliman (9/9) Nov 28 2015 And the second question. Why I am getting next error after
- Suliman (10/19) Nov 28 2015 Eghm, sorry. Not req, but res, but again errr:
- anonymous (3/12) Nov 28 2015 req is not an HTTPClientRequest, it's an HTTPServerRequest.
- Suliman (2/18) Nov 28 2015 What difference between HTTPClientRequest and HTTPRequest ?
- Suliman (4/4) Nov 28 2015 And also I can't understand difference between HTTPClientRequest
- Suliman (6/6) Nov 28 2015 void action(HTTPServerRequest req, HTTPServerResponse res)
- Sebastiaan Koppe (3/9) Nov 28 2015 Wrong logic. Its the server that gets the request and the server
- Sebastiaan Koppe (5/7) Nov 28 2015 If the application (vibe.d) makes a request, it is the client. If
- Suliman (4/11) Nov 28 2015 Could you explain me about: HTTPServerRequest and HTTPRequest. I
- Sebastiaan Koppe (3/16) Nov 30 2015 No idea. Probably HTTPRequest provides common functionality for
- Sebastiaan Koppe (4/9) Nov 28 2015 What you want is `req.json`.
- anonymous (3/12) Nov 28 2015 That's because writeJsonBody's return type is void.
- Jack Applegame (9/24) Dec 02 2015 If you do not send any response in handler, vibe.d will try to
Could anybody help me to understand how to complete HTTP response with vibed. I am sending POST request from AngularJS: $.post("http://127.0.0.1:8080/my", total_result); where total_result is JSON string: [{"QID":3,"AID":3}, {"SubAID":[4]}, {"MinArea":"10","MaxArea":"90"}] Handler is look like: void action(HTTPServerRequest req, HTTPServerResponse res) { // res.statusCode = 201; } I know that I can set statusCode like code above, but problem that in Chrome console I am getting: POST http://127.0.0.1:8080/my 404 (Not Found) How can I pass to it (from vibed to browser) status code?
Nov 28 2015
And the second question. Why I am getting next error after attempt to write to console JSON request: Error: cannot resolve type for res.writeJsonBody(T)(T data int status = HTTPStatus.OK, string content_type = "application/json; charset=UF-8", bool allow_chunked = false) void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(res.writeJsonBody); }
Nov 28 2015
On Saturday, 28 November 2015 at 18:46:05 UTC, Suliman wrote:And the second question. Why I am getting next error after attempt to write to console JSON request: Error: cannot resolve type for res.writeJsonBody(T)(T data int status = HTTPStatus.OK, string content_type = "application/json; charset=UF-8", bool allow_chunked = false) void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(res.writeJsonBody); }Eghm, sorry. Not req, but res, but again errr: void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(req.writeJsonBody); } Error: no property 'writeJsonBody' for type 'vibe.http.server.HTTPServerRequest' But this method are present in docs: http://vibed.org/api/vibe.http.client/HTTPClientRequest
Nov 28 2015
On 28.11.2015 19:51, Suliman wrote:Eghm, sorry. Not req, but res, but again errr: void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(req.writeJsonBody); } Error: no property 'writeJsonBody' for type 'vibe.http.server.HTTPServerRequest' But this method are present in docs: http://vibed.org/api/vibe.http.client/HTTPClientRequestreq is not an HTTPClientRequest, it's an HTTPServerRequest. http://vibed.org/api/vibe.http.server/HTTPServerRequest
Nov 28 2015
On Saturday, 28 November 2015 at 18:57:53 UTC, anonymous wrote:On 28.11.2015 19:51, Suliman wrote:What difference between HTTPClientRequest and HTTPRequest ?Eghm, sorry. Not req, but res, but again errr: void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(req.writeJsonBody); } Error: no property 'writeJsonBody' for type 'vibe.http.server.HTTPServerRequest' But this method are present in docs: http://vibed.org/api/vibe.http.client/HTTPClientRequestreq is not an HTTPClientRequest, it's an HTTPServerRequest. http://vibed.org/api/vibe.http.server/HTTPServerRequest
Nov 28 2015
And also I can't understand difference between HTTPClientRequest and HTTPServerRequest For example if I am getting request from web-browser what I should use? And why?
Nov 28 2015
void action(HTTPServerRequest req, HTTPServerResponse res) { } Here is function what have two call-backs. When it's get request it's work as server, when it's send response it's work like client or I have wrong logic?
Nov 28 2015
On Saturday, 28 November 2015 at 19:10:17 UTC, Suliman wrote:void action(HTTPServerRequest req, HTTPServerResponse res) { } Here is function what have two call-backs. When it's get request it's work as server, when it's send response it's work like client or I have wrong logic?Wrong logic. Its the server that gets the request and the server that send the response.
Nov 28 2015
On Saturday, 28 November 2015 at 19:05:59 UTC, Suliman wrote:And also I can't understand difference between HTTPClientRequest and HTTPServerRequestIf the application (vibe.d) makes a request, it is the client. If the request is made to your application, it is the server. In your case your angular app is the client, and your vibe.d app is the server. Therefor, HTTPServer(Request|Response).
Nov 28 2015
On Saturday, 28 November 2015 at 23:21:21 UTC, Sebastiaan Koppe wrote:On Saturday, 28 November 2015 at 19:05:59 UTC, Suliman wrote:Could you explain me about: HTTPServerRequest and HTTPRequest. I can't understand difference.And also I can't understand difference between HTTPClientRequest and HTTPServerRequestIf the application (vibe.d) makes a request, it is the client. If the request is made to your application, it is the server. In your case your angular app is the client, and your vibe.d app is the server. Therefor, HTTPServer(Request|Response).
Nov 28 2015
On Sunday, 29 November 2015 at 07:37:56 UTC, Suliman wrote:On Saturday, 28 November 2015 at 23:21:21 UTC, Sebastiaan Koppe wrote:No idea. Probably HTTPRequest provides common functionality for both HTTPServerRequest and HTTPClientRequest. Just guessing.On Saturday, 28 November 2015 at 19:05:59 UTC, Suliman wrote:Could you explain me about: HTTPServerRequest and HTTPRequest. I can't understand difference.And also I can't understand difference between HTTPClientRequest and HTTPServerRequestIf the application (vibe.d) makes a request, it is the client. If the request is made to your application, it is the server. In your case your angular app is the client, and your vibe.d app is the server. Therefor, HTTPServer(Request|Response).
Nov 30 2015
On Saturday, 28 November 2015 at 18:51:57 UTC, Suliman wrote:Eghm, sorry. Not req, but res, but again errr: void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(req.writeJsonBody); }What you want is `req.json`. Make sure that the call from angular sets the Content-Type header to application/json. But I think that should happen by default.
Nov 28 2015
On 28.11.2015 19:46, Suliman wrote:And the second question. Why I am getting next error after attempt to write to console JSON request: Error: cannot resolve type for res.writeJsonBody(T)(T data int status = HTTPStatus.OK, string content_type = "application/json; charset=UF-8", bool allow_chunked = false) void action(HTTPServerRequest req, HTTPServerResponse res) { writeln(res.writeJsonBody); }That's because writeJsonBody's return type is void. http://vibed.org/api/vibe.http.server/HTTPServerResponse.writeJsonBody
Nov 28 2015
On Saturday, 28 November 2015 at 18:03:13 UTC, Suliman wrote:Could anybody help me to understand how to complete HTTP response with vibed. I am sending POST request from AngularJS: $.post("http://127.0.0.1:8080/my", total_result); where total_result is JSON string: [{"QID":3,"AID":3}, {"SubAID":[4]}, {"MinArea":"10","MaxArea":"90"}] Handler is look like: void action(HTTPServerRequest req, HTTPServerResponse res) { // res.statusCode = 201; } I know that I can set statusCode like code above, but problem that in Chrome console I am getting: POST http://127.0.0.1:8080/my 404 (Not Found) How can I pass to it (from vibed to browser) status code?If you do not send any response in handler, vibe.d will try to match next route (if any). So you should send any response (empty string for example). void action(HTTPServerRequest req, HTTPServerResponse res) { res.statusCode = 201; res.writeBody(""); }
Dec 02 2015