-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBaseConnect.js
80 lines (62 loc) · 1.81 KB
/
DataBaseConnect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
pseudo code for connecting to database
love chat gpt https://chat.openai.com/share/a455b30c-0f44-4baa-8171-602699a0b4ca
use fetch api: https://www.w3schools.com/js/js_api_fetch.asp
c# backend https://dotnet.microsoft.com/en-us/apps/aspnet/apis
host web api on ak's dad's server?
for now, host web api on old laptop
ip address from a dns server routed from the local ip
example here
Make a GET request to fetch user data from the backend
fetch('https://example.com/api/users')
.then(response => response.json())
.then(data => {
// Process the received data
console.log(data);
})
.catch(error => {
// Handle any errors
console.error(error);
});
Make a POST request to create a new user
fetch('https://example.com/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'John Doe',
email: '[email protected]'
})
})
.then(response => response.json())
.then(data => {
// Process the response from the backend
console.log(data);
})
.catch(error => {
// Handle any errors
console.error(error);
});
with this being the backend C# code
Define a route to handle GET requests for fetching users
[HttpGet]
[Route("api/users")]
public IHttpActionResult GetUsers()
{
Retrieve user data from a database or any other data source
var users = ...; // Retrieve users from the backend
// Return the user data as JSON response
return Json(users);
}
Define a route to handle POST requests for creating a new user
[HttpPost]
[Route("api/users")]
public IHttpActionResult CreateUser(UserDto userDto)
{
// Process the received user data and save it to the backend
var user = ...; // Process and save the user to the backend
// Return the created user as JSON response
return Json(user);
}
*/