Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contentstack API #420

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions New_APIs/ContentStack API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>ContentStack API </title>
</head>
<body>
<header>
<h1>ContentStack API</h1>
</header>
<main>
<div class="content-section">
<h2>Select Content Type</h2>
<input type="text" id="contentType" placeholder="Enter Content Type UID">
<button id="fetchContentButton">Fetch Content</button>
</div>
<div class="result-section">
<h2>Content Entries</h2>
<ul id="contentList"></ul>
</div>
</main>
<script src="index.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions New_APIs/ContentStack API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
document.getElementById('fetchContentButton').addEventListener('click', fetchContent);

const apiKey = 'YOUR_API_KEY'; // Replace with your ContentStack API key
const accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with your ContentStack access token
const apiUrl = 'https://cdn.contentstack.io/v3/content_types';

async function fetchContent() {
const contentType = document.getElementById('contentType').value;

if (!contentType) {
alert('Please enter a Content Type UID.');
return;
}

try {
const response = await fetch(`${apiUrl}/${contentType}/entries`, {
method: 'GET',
headers: {
'api_key': apiKey,
'access_token': accessToken,
'Content-Type': 'application/json'
}
});

if (response.ok) {
const result = await response.json();
displayContent(result.entries);
} else {
alert('Failed to fetch content.');
}
} catch (error) {
console.error('Error:', error);
alert('Error fetching content.');
}
}

function displayContent(entries) {
const contentList = document.getElementById('contentList');
contentList.innerHTML = '';

if (entries.length === 0) {
contentList.innerHTML = '<li>No entries found.</li>';
return;
}

entries.forEach(entry => {
const listItem = document.createElement('li');
listItem.textContent = JSON.stringify(entry, null, 2);
contentList.appendChild(listItem);
});
}
26 changes: 26 additions & 0 deletions New_APIs/ContentStack API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions New_APIs/ContentStack API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "contentstack-api-demo",
"version": "1.0.0",
"description": "A simple app to demonstrate the ContentStack API",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"contentstack-api-demo": "file:",
"express": "^4.17.1"
}
}
8 changes: 8 additions & 0 deletions New_APIs/ContentStack API/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');
const app = express();

app.use(express.static('public'));

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
79 changes: 79 additions & 0 deletions New_APIs/ContentStack API/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #f14a7f, #35d1dc);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}

header {
text-align: center;
margin-bottom: 20px;
}

header h1 {
font-size: 3em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

main {
width: 90%;
max-width: 600px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.content-section,
.result-section {
margin-bottom: 20px;
text-align: center;
}

input[type="text"] {
display: block;
margin: 0 auto 15px auto;
font-size: 1em;
border: none;
border-radius: 5px;
outline: none;
padding: 10px;
width: 80%;
max-width: 400px;
}

button {
padding: 10px 20px;
font-size: 1em;
background-color: #444;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #666;
}

.result-section ul {
list-style-type: none;
padding: 0;
text-align: left;
margin-top: 15px;
}

.result-section ul li {
background: rgba(0, 0, 0, 0.2);
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
word-wrap: break-word;
}
Loading