Skip to content

Commit

Permalink
Merge pull request #38 from Vibgitcode27/master
Browse files Browse the repository at this point in the history
API Enhancement
  • Loading branch information
dishamodi0910 authored Oct 15, 2023
2 parents 54ec2b4 + 6d14582 commit aa39d2d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Existing_API_Collection/CountryAPI/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
11 changes: 11 additions & 0 deletions Existing_API_Collection/CountryAPI/country.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ body{
color: #ff465a;
}

#clear-btn
{
font-size: 1em;
background-color: #3d64e6;
color: #ffffff;
padding: 0.8em 0;
border: none;
border-radius: 1.5em;
cursor: pointer;
width: 8em;
}
1 change: 0 additions & 1 deletion Existing_API_Collection/CountryAPI/country.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</div>
<div id="result"></div>
</div>

<script src="country.js"></script>
</body>
</html>
13 changes: 11 additions & 2 deletions Existing_API_Collection/CountryAPI/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ searchBtn.addEventListener("click",()=>{
<h4>Common Languages : </h4>
<span>${Object.values(data[0].languages).toString().split(",").join(", ")}</span>
</div>
</div>`;
</div>
<button id="clear-btn">Close</button>
`;
})
.catch(()=>{
if(countryName.length == 0){
Expand All @@ -60,4 +62,11 @@ searchBtn.addEventListener("click",()=>{
result.innerHTML=`<h3>Please enter a valid country name.</h3>`;
}
});
});
});

document.addEventListener("click", function(e) {
if (e.target && e.target.id === "clear-btn") {
result.innerHTML = "";
}
});

4 changes: 3 additions & 1 deletion Existing_API_Collection/GiphyAPI/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ main {
#gif-container {
display: flex;
flex-wrap: wrap;
padding: 50px 80px;
justify-content: center;
}

.gif-item {
margin: 10px;
max-width: 250px;
max-width: fit-content;
height: fit-content;
text-align: center;
background-color: #fff;
border: 1px solid #ddd;
Expand Down
6 changes: 3 additions & 3 deletions New_APIs/Demo_CRUD_API/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build" : "tsc ",
"start" : "tsc & node .",
"dev" : "tsc -w & nodemon ."
"build": "tsc ",
"start": "tsc & node .",
"dev": "tsc -w & nodemon ."
},
"keywords": [],
"author": "",
Expand Down
18 changes: 9 additions & 9 deletions New_APIs/Demo_CRUD_API/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
var express = require('express');
var dotenv = require('dotenv');
dotenv.config();
var app = express();
var port = process.env.PORT || 3000;
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json()); //Middleware
var users = [
const users = [
{
"id": 1,
"name": 'Johnny1'
Expand All @@ -26,7 +26,7 @@ app.get("/user", function (req, res) {
});
//CREATE USER
app.post("/user", function (req, res) {
var newUser = {
const newUser = {
name: req.body.name,
id: Date.now(),
};
Expand All @@ -35,7 +35,7 @@ app.post("/user", function (req, res) {
});
//UPDATE
app.put("/user", function (req, res) {
var _a = req.body, id = _a.id, name = _a.name;
let _a = req.body, id = _a.id, name = _a.name;
users = users.map(function (user) {
if (user.id === id) {
user.name = name;
Expand All @@ -45,12 +45,12 @@ app.put("/user", function (req, res) {
});
//DELETE
app.delete("/user/:id", function (req, res) {
var id = req.params.id;
let id = req.params.id;
users = users.filter(function (user) { return user.id !== Number(id); });
res.json(users);
});
var isAuthorized = function (req, res, next) {
var authHeader = req.headers.authorization;
const authHeader = req.headers.authorization;
if (authHeader === 'gdscdemocrudapi') {
next();
}
Expand All @@ -61,8 +61,8 @@ var isAuthorized = function (req, res, next) {
};
//GET USER BY ID
app.get("/user/:id", isAuthorized, function (req, res) {
var id = req.params.id;
var user = users.find(function (user) { return user.id === Number(id); });
let id = req.params.id;
const user = users.find(function (user) { return user.id === Number(id); });
res.json(user);
});
//Start the app
Expand Down

0 comments on commit aa39d2d

Please sign in to comment.