Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function request(url = "/", method = "POST", body) {
- let input = {
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- method
- };
- if (body) {
- input.body = JSON.stringify(body);
- }
- fetch(`http://localhost:8080${url}`, input)
- .then((res) => res.json())
- .then((res) => console.log(res))
- .catch((err) => console.log(err))
- }
- function request(url = "/", method = "POST", body) {
- let input = {
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- method
- };
- if (body) {
- input.body = JSON.stringify(body);
- }
- fetch(`http://localhost:8080${url}`, input)
- .then(res => {
- const contentType = res.headers.get("content-type");
- if (contentType && contentType.indexOf("application/json") !== -1) {
- return res.json().then(data => {
- console.log(data);
- });
- }
- })
- .catch((err) => console.log(err))
- }
- request("/users/login", "POST", {username: "Danya", password: 123})
- request("/sample/2", "PUT", {columnA: "Haven", columnB:"Dorre", columnC: "Green", columnD: "Somali", columnE: "L", id:2})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement