Skip to content

Instantly share code, notes, and snippets.

@allefgomes
Created March 2, 2020 02:08
Show Gist options
  • Save allefgomes/7fc608745b216ab95c22669866f3c99c to your computer and use it in GitHub Desktop.
Save allefgomes/7fc608745b216ab95c22669866f3c99c to your computer and use it in GitHub Desktop.
Api service with axios-observable
import Axios from "axios-observable";
const url_base = "http://10.0.0.104:3000"
export default {
create(url, params) {
Axios.post(url_base + url, params)
.subscribe(
response => console.log(response),
error => {
console.log(error);
// TODO: Create a method to handle errors
}
);
},
show(url) {
Axios.get(url_base + url)
.subscribe(
response => console.log(response),
error => {
console.log(error);
// TODO: Create a method to handle errors
}
);
},
update(url, params) {
Axios.put(url_base + url, params)
.subscribe(
response => console.log(response),
error => {
console.log(error);
// TODO: Create a method to handle errors
}
);
},
delete(url) {
Axios.delete(url_base + url)
.subscribe(
response => console.log(response),
error => {
console.log(error);
// TODO: Create a method to handle errors
}
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment