
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Welcome to the Hero API npm package! This library provides a simple and efficient way to interact with the Hero Platform, a free online platform for creating and sharing content including blogs, photos, files, and more.
To try this API online, go to the Hero API Playground
To find your API Key:
Whether you're building a personal project, promoting a business, organizing an event, or fostering a community, the Hero API lets you take control of your content in a programmable way. Enhance your project with the rich features that Hero Platform offers!
When using hero-api
, please ensure that your project is configured to use ES modules. This can be done in one of two ways:
Using .mjs
Extension: Name your files with the .mjs
extension to explicitly mark them as ES modules.
Setting "type": "module"
in package.json
: Include the "type": "module"
key-value pair in your project's package.json
file. This will treat all .js
files in your project as ES modules.
hero-api
Once you've configured your project to use ES modules, you can import hero-api
using the following syntax:
import { HeroAPI } from 'hero-api';
import { HeroAPI } from "hero-api";
const hero = new HeroAPI('YOUR_API_TOKEN');
const DEFAULT_SPACE_IMG = "https://picsum.photos/600/500";
async function createContent() {
let testsPassed = 0;
let failedTests = [];
try {
// Creating Space
const spaceResponse = await hero.createSpace('Amazing Space', true, DEFAULT_SPACE_IMG);
console.log('Space created:', spaceResponse);
testsPassed++;
const spaceId = spaceResponse.id;
// Getting Space
const getSpaceResponse = await hero.getSpace(spaceId);
console.log('Space fetched:', getSpaceResponse);
testsPassed++;
// Updating Space
const updateSpaceResponse = await hero.updateSpace(spaceId, { name: 'Updated Space', isPublic: true, img: "https://picsum.photos/600/400" });
console.log('Space updated:', updateSpaceResponse);
testsPassed++;
// Creating List
const listResponse = await hero.createList(spaceId, 'My List', '#FF5733');
console.log('List created:', listResponse);
testsPassed++;
const listId = listResponse.id;
// Getting List
const getListResponse = await hero.getList(spaceId, listId);
console.log('List fetched:', getListResponse);
testsPassed++;
// Updating List
const updateListResponse = await hero.updateList(spaceId, listId, 'Updated List', '#00FF00');
console.log('List updated:', updateListResponse);
testsPassed++;
// Listing Lists
const listListsResponse = await hero.listLists(spaceId);
console.log('Lists fetched:', listListsResponse);
testsPassed++;
// Creating Item
const itemRequestBody = {
listId: listId,
title: 'My first Item',
// other attributes as needed
};
const itemResponse = await hero.createItem(spaceId, itemRequestBody);
console.log('Item created:', itemResponse);
testsPassed++;
// Getting Item
const itemId = itemResponse.id; // Assuming itemResponse contains the item ID
const getItemResponse = await hero.getItem(spaceId, itemId);
console.log('Item fetched:', getItemResponse);
testsPassed++;
// Updating Item
const updateItemRequestBody = {
title: 'Updated Item titleee'
// other attributes as needed
};
await hero.updateItem(spaceId, itemId, updateItemRequestBody);
console.log('Item updated');
testsPassed++;
// Deleting Item
await hero.deleteItem(spaceId, itemId);
console.log('Item deleted');
testsPassed++;
// Deleting List
await hero.deleteList(spaceId, listId);
console.log('List deleted');
testsPassed++;
// Deleting Space
await hero.deleteSpace(spaceId);
console.log('Space deleted');
testsPassed++;
console.log('Tests passed:', testsPassed);
} catch (error) {
console.error('An error occurred:', error);
failedTests.push(error.message);
console.log('Failed tests:', failedTests);
}
}
createContent();
async function createRandomContent() {
try {
// Creating Space
const spaceResponse = await hero.createSpace('Amazing Random Space', true);
console.log('Space created:', spaceResponse);
const spaceId = spaceResponse.id;
// Generate random colors
function getRandomColor() {
return "#" + Math.floor(Math.random() * 16777215).toString(16);
}
// Creating 4 Lists
for (let i = 1; i <= 4; i++) {
const listName = 'Random List ' + i;
const listColor = getRandomColor();
const listResponse = await hero.createList(spaceId, listName, listColor);
console.log('List created:', listResponse);
const listId = listResponse.id;
// Creating 5 Items for each List
for (let j = 1; j <= 5; j++) {
const itemTitle = 'Random Item ' + j;
const itemRequestBody = {
listId: listId,
title: itemTitle,
};
const itemResponse = await hero.createItem(spaceId, itemRequestBody);
console.log('Item created:', itemResponse);
}
}
} catch (error) {
console.error('An error occurred:', error);
}
}
createRandomContent();
async function uploadImageAndLogURL() {
const base64Image = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFM..."; // Not a real base64 string, can find one with a quick google search!
const response = await hero.uploadImage(base64Image, "ExampleImage");
if (response.url) {
console.log('Image uploaded successfully:', response.url);
} else {
console.log('Error uploading image:', response);
}
}
uploadImageAndLogURL();
FAQs
API for Hero Spaces, Lists & Items (https://hero.page)
The npm package hero-api receives a total of 2 weekly downloads. As such, hero-api popularity was classified as not popular.
We found that hero-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.