A simple rest client implemented in JavaScript.
rest("http://localhost")
.get()
.then(success => console.log(success), error => console.log(error));
rest("http://localhost")
.query({ param: "value" })
.get()
.then(success => console.log(success), error => console.log(error));
GET "http://localhost/?param=value"
rest("http://localhost")
.headers({ "my-special-snowflake-header": "very important stuff" })
.query({ param: "value" })
.get()
.then(success => console.log(success), error => console.log(error));
let client = rest("http://localhost/api")
.route("test", "/users/{userId}/offices/{officeId}")
.route("bla", "/bla/{txt}");
client.routes.test
.parameters({ userId: 10, officeId: 20 })
.query({ bla: 10 })
.post();
client.routes.bla
.parameters({ txt: "some txt" })
.get();
POST "http://localhost/api/users/10/offices/20?bla=10"
GET "http://localhost/api/bla/some%20txt"
var usersApi = api("http://localhost/api", {
getUser: {
method: "get",
url: "/users/{userId}"
},
createUser: {
method: "post",
url: "/users"
}
});
usersApi.getUser({ parameters: { userId: 10 }, query: { test: 1, bla: "10" } })
usersApi.createUser({ body: { name: "Ivan", age: 21 } });
GET "http://localhost/api/users/10?test=1&bla=10"
POST "http://localhost/api/users"