Skip to content

Instantly share code, notes, and snippets.

@SPavelV
Created September 18, 2021 04:51
Show Gist options
  • Select an option

  • Save SPavelV/54f56098e63a82b33479b678ee58904a to your computer and use it in GitHub Desktop.

Select an option

Save SPavelV/54f56098e63a82b33479b678ee58904a to your computer and use it in GitHub Desktop.
Swagger api demo
<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport'
content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>Lectrum LLC</title>
</head>
<body>
<script>
// Create
(async () => {
const response = await fetch('https://lab.lectrum.io/examples/api/swagger/customers', {
method: 'POST',
headers: {
authorization: '1qazxsw2',
'content-type': 'application/json'
},
body: JSON.stringify({ name: 'Андрей' })
});
if (!response.ok) {
console.error('Запрос не удался');
return;
}
const data = await response.json();
console.log(data);
})();
// Create
// Get ALL
// (async () => {
// const limit = 10;
// const page = 1;
// const response = await fetch(`https://lab.lectrum.io/examples/api/swagger/customers?limit=${limit}&page=${page}`);
// if (!response.ok) {
// console.error('Запрос не удался');
// return;
// }
// const data = await response.json();
// console.log(data);
// })();
// Get ALL
// Get by ID
// (async () => {
// const userId = 'b575adc5-2e5a-478a-935e-ca7430f1e05f';
// const response = await fetch(`https://lab.lectrum.io/examples/api/swagger/customers/${userId}`);
// if (!response.ok) {
// console.error('Запрос не удался');
// return;
// }
// const data = await response.json();
// console.log(data);
// })();
// Get by ID
// Update
// (async () => {
// const userId = 'b575adc5-2e5a-478a-935e-ca7430f1e05f';
// const response = await fetch(`https://lab.lectrum.io/examples/api/swagger/customers/${userId}`, {
// method: 'PUT',
// headers: {
// 'content-type': 'application/json'
// },
// body: JSON.stringify({ name: 'Джон' })
// });
// if (!response.ok) {
// console.error('Запрос не удался');
// return;
// }
// const data = await response.json();
// console.log(data);
// })();
// Update
// Delete
// (async () => {
// const userId = 'b575adc5-2e5a-478a-935e-ca7430f1e05f';
// const response = await fetch(`https://lab.lectrum.io/examples/api/swagger/customers/${userId}`, {
// method: 'DELETE',
// });
// if (!response.ok) {
// console.error('Запрос не удался');
// return;
// }
// console.log('Пользователь успешно удалён');
// })();
// Delete
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment