readme updated

This commit is contained in:
Vladimir Enchev
2014-05-23 11:33:22 +03:00
parent de2bf37b15
commit 0220d130f4
2 changed files with 4 additions and 59 deletions

View File

@ -219,7 +219,8 @@ export var test_request_responseContentShouldBeDefined = function () {
// ### Get response content
// ``` JavaScript
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
//// Argument (response) is HttpContent!
//// Argument (response) is HttpResponse!
//// Content property of the response is HttpContent!
var str = response.content.toString();
var obj = response.content.toJSON();
var img = response.content.toImage();

View File

@ -23,62 +23,6 @@
toJSON: () => any;
toImage: () => image_module.Image;
}
```
// GET request
http.request({
url: "http://ip.jsontest.com/",
method: "GET",
headers: { "Content-Type" : "application/json" }
}).then(function (r) {
var status = r.statusCode;
for (var header in r.headers) {
//
}
var result = r.content.toJSON();
}).fail(function (e) { console.log(e) });
// POST request
http.request({
url: "http://posttestserver.com/post.php?dump&html&dir=test",
method: "POST",
headers: { "Content-Type" : "application/x-www-form-urlencoded" },
content: "MyVariableOne=ValueOne&MyVariableTwo=ValueTwo"
}).then(function (r) {
var status = r.statusCode;
for (var header in r.headers) {
//
}
var result = r.content.toString();
}).fail(function (e) { console.log(e) });
// PUT request
var data = YOUR_IMAGE_DATA;
http.request({
url: "http://httpbin.org/put",
method: "PUT",
headers: {
"Content-Type": "image/jpg",
"Content-Length": data.length() + ""
},
content: data
}).then(function (r) {
console.log(r.content.toString())
}).fail(function (e) { console.log(e) });
http.getString("http://www.reddit.com/").then(function(result) {
// Result is string!
}).fail(function(e) { console.log(e); });
http.getJSON("http://www.reddit.com/r/aww.json?limit=10").then(function(result) {
// Result is JSON!
}).fail(function(e) { console.log(e); });
http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function(result) {
// Result is tk.ui.Image!
}).fail(function(e) { console.log(e); });
```
More info: https://github.com/telerik/xPlatCore/blob/master/Documentation/Snippets/http.md