Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions src/data/community-apis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"API": "IP Geolocation API",
"Description": "Returns country, city, ISP, coordinates, and timezone for any IP address",
"Auth": "apiKey",
"HTTPS": true,
"Cors": "yes",
"Link": "https://api-catalog-three.vercel.app/services/ip-geolocation-api",
"Category": "Geocoding"
},
{
"API": "Frostbyte Crypto Price API",
"Description": "Real-time prices, market cap, and 24h changes for 150+ cryptocurrencies",
"Auth": "apiKey",
"HTTPS": true,
"Cors": "yes",
"Link": "https://api-catalog-three.vercel.app/services/crypto-price-api",
"Category": "Cryptocurrency"
},
{
"API": "Frostbyte Screenshot API",
"Description": "Capture full-page or viewport website screenshots programmatically",
"Auth": "apiKey",
"HTTPS": true,
"Cors": "yes",
"Link": "https://api-catalog-three.vercel.app/services/screenshot-api",
"Category": "Development"
},
{
"API": "Frostbyte Web Scraping API",
"Description": "Extract structured data from any webpage using CSS selectors",
"Auth": "apiKey",
"HTTPS": true,
"Cors": "yes",
"Link": "https://api-catalog-three.vercel.app/services/web-scraping-api",
"Category": "Development"
}
]
16 changes: 10 additions & 6 deletions src/pages/Browse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ListDisplay from '../../components/ListDisplay';
import { debounce } from 'lodash';
import ScrollUp from '../../components/ScrollUp';
import LoadingScreen from '../LoadingScreen';
import communityApis from '../../data/community-apis.json';

function Browse() {
const [apis, setApis] = useState();
Expand Down Expand Up @@ -74,21 +75,24 @@ function Browse() {
}
}, [refresh, canStore, backup]);

const mergeWithCommunity = (entries) => {
const combined = [...entries, ...communityApis];
return [
...new Map(combined.map((api) => [api['API'], api])).values(),
];
};

const setCache = (result) => {
let value = result['entries'];
const unique = [
...new Map(value.map((api) => [api['API'], api])).values(),
];
const unique = mergeWithCommunity(value);
const uniqueString = JSON.stringify(unique);
sessionStorage.setItem('data', uniqueString);
setApis(unique);
};

const handleBackup = (result) => {
let value = result['entries'];
const unique = [
...new Map(value.map((api) => [api['API'], api])).values(),
];
const unique = mergeWithCommunity(value);
setBackup(unique);
setApis(unique);
};
Expand Down
24 changes: 16 additions & 8 deletions src/pages/Categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import ScrollUp from '../../components/ScrollUp';
import Help from '../../components/Help';
import communityApis from '../../data/community-apis.json';

function Categories() {
const [categories, setCategories] = useState([]);
Expand Down Expand Up @@ -32,16 +33,23 @@ function Categories() {
categoryCached = sessionStorage.getItem('categories');
}

const communityCategories = [
...new Set(communityApis.map((api) => api.Category)),
];

if (!categoryCached) {
fetch('https://api.publicapis.org/categories')
.then((response) => response.json())
.then(
(data) => {
setCategories(data.categories);
const merged = [
...new Set([...data.categories, ...communityCategories]),
].sort();
setCategories(merged);
if (canStore) {
sessionStorage.setItem(
'categories',
JSON.stringify(data.categories),
JSON.stringify(merged),
);
}
},
Expand All @@ -63,7 +71,7 @@ function Categories() {
</div>
</div>
<div
className='flex justify-center text-xl m-4 p-4
className='flex justify-center text-xl m-4 p-4
animate-pulse'
>
The API categories weren't able to be loaded. Reload or try
Expand All @@ -76,20 +84,20 @@ function Categories() {
return (
<Template>
<div
className='flex justify-center text-2xl sm:text-3xl m-4
className='flex justify-center text-2xl sm:text-3xl m-4
mt-6'
>
<div className='border-b-2 border-gray-400 border-solid'>
API Categories
</div>
</div>
<div
className='m-4 sm:m-6 mt-0 sm:mt-0 flex flex-wrap
className='m-4 sm:m-6 mt-0 sm:mt-0 flex flex-wrap
justify-center'
>
{categories.map((category) => (
<Link
className='text-lg rounded-lg p-3 m-3 bg-gray-200
className='text-lg rounded-lg p-3 m-3 bg-gray-200
w-64 text-center shadow-lg hover:shadow-xl
cursor-pointer hover:bg-gray-100'
key={category}
Expand All @@ -99,8 +107,8 @@ function Categories() {
</Link>
))}
<Link
className='text-lg rounded-lg p-3 m-3 bg-gray-300
w-64 text-center shadow-lg hover:shadow-xl
className='text-lg rounded-lg p-3 m-3 bg-gray-300
w-64 text-center shadow-lg hover:shadow-xl
cursor-pointer hover:bg-gray-200'
to={`/browse`}
>
Expand Down
16 changes: 10 additions & 6 deletions src/pages/Category/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ListDisplay from '../../components/ListDisplay';
import { useParams } from 'react-router';
import { Link } from 'react-router-dom';
import ScrollUp from '../../components/ScrollUp';
import communityApis from '../../data/community-apis.json';

function Category() {
const [apis, setApis] = useState([]);
Expand Down Expand Up @@ -72,21 +73,24 @@ function Category() {
}
}, [refresh, canStore, backup]);

const mergeWithCommunity = (entries) => {
const combined = [...entries, ...communityApis];
return [
...new Map(combined.map((api) => [api['API'], api])).values(),
];
};

const onSetResult = (result) => {
let value = result['entries'];
const unique = [
...new Map(value.map((api) => [api['API'], api])).values(),
];
const unique = mergeWithCommunity(value);
const uniqueString = JSON.stringify(unique);
sessionStorage.setItem('data', uniqueString);
setApis(unique);
};

const onSetResultBackup = (result) => {
let value = result['entries'];
const unique = [
...new Map(value.map((api) => [api['API'], api])).values(),
];
const unique = mergeWithCommunity(value);
setBackup(unique);
setApis(unique);
};
Expand Down