aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-26 19:09:13 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-26 19:09:13 -0600
commit4fbd330a17cf388c82bfc1dbfe1122593cbdc1b5 (patch)
treec55f4cfd8ade3d38b41c86e729a2c8027052992c /src
parent8021e53f6327f11d0012ed20fd429c197636869f (diff)
downloadToDo-App-FE-4fbd330a17cf388c82bfc1dbfe1122593cbdc1b5.tar.gz
ToDo-App-FE-4fbd330a17cf388c82bfc1dbfe1122593cbdc1b5.zip
Using Axios to send HTTP requests.
Defining API and method GET to retrieve all to dos.
Diffstat (limited to '')
-rw-r--r--src/api/axios_config.js8
-rw-r--r--src/api/axios_methods.js15
2 files changed, 23 insertions, 0 deletions
diff --git a/src/api/axios_config.js b/src/api/axios_config.js
new file mode 100644
index 0000000..1ecde93
--- /dev/null
+++ b/src/api/axios_config.js
@@ -0,0 +1,8 @@
+import axios from "axios";
+
+export default axios.create({
+ baseURL: "http://localhost:9090/",
+ headers: {
+ "Content-Type": "application/json",
+ },
+});
diff --git a/src/api/axios_methods.js b/src/api/axios_methods.js
new file mode 100644
index 0000000..2e2329f
--- /dev/null
+++ b/src/api/axios_methods.js
@@ -0,0 +1,15 @@
+import api from "./axios_config";
+
+// findAll() on Back End.
+export function get_todos_function(hook) {
+ // Get a list of all to dos.
+ // GET "/v1/todos"
+ return async () => {
+ try {
+ const response = await api.get("/v1/todos");
+ hook(response.data);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+}