Here's a more detailed README.md
that covers all aspects of the Laava API Wrapper
package:
Laava API Wrapper is a Node.js package that provides a convenient interface for interacting with the Laava API. It simplifies the process of managing collections, tags, and metadata through intuitive methods and comprehensive error handling.
- Collections Management: Easily create, retrieve, update, and delete collections.
- Tagging System: Manage tags associated with your resources, allowing for better organization.
- Metadata Handling: Store and retrieve metadata efficiently for various resources.
- Promise-based: Utilizes promises for asynchronous operations, making it easy to integrate into modern Node.js applications.
- Error Handling: Comprehensive error handling to help you manage API errors gracefully.
To install the package, use npm:
npm install laava-api-wrapper
To start using the Laava API Wrapper, you need to instantiate the LaavaAPI
class with your API key.
const LaavaAPI = require('laava-api-wrapper');
const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
const laavaAPI = new LaavaAPI(apiKey);
Manage collections with the following methods:
// Fetch all collections
const collections = await laavaAPI.getCollections();
// Fetch a collection by ID
const collection = await laavaAPI.getCollectionById('collectionId');
// Create a new collection
const newCollection = { name: 'New Collection', description: 'Description' };
const createdCollection = await laavaAPI.createCollection(newCollection);
// Update an existing collection
const updatedData = { name: 'Updated Collection' };
const updatedCollection = await laavaAPI.updateCollection('collectionId', updatedData);
// Delete a collection
await laavaAPI.deleteCollection('collectionId');
Manage tags with the following methods:
// Fetch all tags
const tags = await laavaAPI.getTags();
// Fetch a tag by ID
const tag = await laavaAPI.getTagById('tagId');
// Create a new tag
const newTag = { name: 'New Tag' };
const createdTag = await laavaAPI.createTag(newTag);
// Update an existing tag
const updatedTagData = { name: 'Updated Tag' };
const updatedTag = await laavaAPI.updateTag('tagId', updatedTagData);
// Delete a tag
await laavaAPI.deleteTag('tagId');
Manage metadata with the following methods:
// Fetch all metadata
const metadata = await laavaAPI.getMetadata();
// Fetch metadata by ID
const singleMetadata = await laavaAPI.getMetadataById('metadataId');
// Create new metadata
const newMetadata = { key: 'exampleKey', value: 'exampleValue' };
const createdMetadata = await laavaAPI.createMetadata(newMetadata);
// Update existing metadata
const updatedMetadataData = { value: 'updatedValue' };
const updatedMetadata = await laavaAPI.updateMetadata('metadataId', updatedMetadataData);
// Delete metadata
await laavaAPI.deleteMetadata('metadataId');
getCollections()
: Retrieves all collections.getCollectionById(collectionId)
: Retrieves a specific collection by its ID.createCollection(data)
: Creates a new collection with the provided data.updateCollection(collectionId, data)
: Updates an existing collection with new data.deleteCollection(collectionId)
: Deletes a collection by its ID.
getTags()
: Retrieves all tags.getTagById(tagId)
: Retrieves a specific tag by its ID.createTag(data)
: Creates a new tag with the provided data.updateTag(tagId, data)
: Updates an existing tag with new data.deleteTag(tagId)
: Deletes a tag by its ID.
getMetadata()
: Retrieves all metadata.getMetadataById(metadataId)
: Retrieves specific metadata by its ID.createMetadata(data)
: Creates new metadata with the provided data.updateMetadata(metadataId, data)
: Updates existing metadata with new data.deleteMetadata(metadataId)
: Deletes metadata by its ID.
The Laava API Wrapper provides comprehensive error handling. All methods return a promise, which will reject if an error occurs during the API call. Errors can be caught using .catch()
or within a try...catch
block.
try {
const collections = await laavaAPI.getCollections();
} catch (error) {
console.error('An error occurred:', error.message);
}
Errors are returned as instances of the Error
class, with additional properties such as statusCode
and response
where applicable.
Here are some examples of how you might use the Laava API Wrapper in different scenarios:
-
Fetching and Logging All Collections:
(async () => { const collections = await laavaAPI.getCollections(); console.log('Collections:', collections); })();
-
Creating and Updating a Tag:
(async () => { const newTag = { name: 'Important Tag' }; const createdTag = await laavaAPI.createTag(newTag); console.log('Created Tag:', createdTag); const updatedTag = await laavaAPI.updateTag(createdTag.id, { name: 'Updated Tag' }); console.log('Updated Tag:', updatedTag); })();
-
Handling Metadata:
(async () => { const metadata = { key: 'color', value: 'blue' }; const createdMetadata = await laavaAPI.createMetadata(metadata); console.log('Created Metadata:', createdMetadata); const updatedMetadata = await laavaAPI.updateMetadata(createdMetadata.id, { value: 'red' }); console.log('Updated Metadata:', updatedMetadata); })();
Contributions are welcome! If you'd like to contribute to the project, follow these steps:
- Fork the repository on GitHub.
- Create a new branch with a descriptive name.
- Make your changes and ensure they are well-documented.
- Submit a pull request with a detailed description of your changes.
Please ensure that your code follows the existing style and conventions of the project.
This project is licensed under the MIT License. See the LICENSE file for more information.
If you have any questions, issues, or suggestions, feel free to reach out:
- Email: ahmad.wali@esipick.com
- GitHub: ahmadwaliesipick