Skip to content

Commit

Permalink
varios, expressjs, js-snippets, nodejs, nodejs-snippets, nodejs-bbdd
Browse files Browse the repository at this point in the history
  • Loading branch information
jolav committed Sep 10, 2024
1 parent 7ea633e commit 869e0b4
Show file tree
Hide file tree
Showing 28 changed files with 480 additions and 1,690 deletions.
2 changes: 1 addition & 1 deletion docs/expressjs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EXPRESS 4.16.X
# EXPRESS 4.20.X

---

Expand Down
36 changes: 36 additions & 0 deletions docs/javascript-snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,42 @@ function objectIsEmpty(obj) {

---

## FETCH

```js
async function fetchData(c, data) {
const options = {
timeout: c.timeout,
host: c.host,
port: c.port,
path: c.api,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Charset': 'utf-8'
},
body: new URLSearchParams({
'key': c.API_KEY,
'data': JSON.stringify(data)
}),
};
const url = c.API_URL + c.API_ENDPOINT;
try {
const response = await fetch(url, options);
if (response.ok) {
const data = await response.json();
return data;
} else {
throw new Error(response.status + " " + response.statusText);
}
} catch (err) {
console.log('ERROR fetchData => ', err);
}
}
```

---

## AJAX REQUESTS

### GET
Expand Down
Loading

0 comments on commit 869e0b4

Please sign in to comment.