@arqam-formsoft/card-sdk
v1.0.1
Published
SDK for interacting with the Card API
Readme
card-sdk
SDK for interacting with the Card API.
Installation
Install the package using npm:
npm install @arqam-formsoft/card-sdkUsage
First, require the package and create an instance of the SDK with the base URL of your API:
const CardSDK = require('@arqam-formsoft/card-sdk');
const sdk = new CardSDK('http://localhost:8000');Functions
createCard(card)
Creates a new card.
Parameters:
card(Object): The card object to create. Example:{ name: 'Test Card', number: 1234 }
Returns:
- The created card object.
Example:
const newCard = await sdk.createCard({ name: 'Test Card', number: 1234 });
console.log('Created Card:', newCard);getCard(id)
Fetches a card by its ID.
Parameters:
id(String): The ID of the card to fetch.
Returns:
- The card object.
Example:
const card = await sdk.getCard('60d5f9b8f8d2e8b5b8f8b8f8');
console.log('Fetched Card:', card);getAllCards()
Fetches all cards.
Returns:
- An array of card objects.
Example:
const allCards = await sdk.getAllCards();
console.log('All Cards:', allCards);updateCard(id, card)
Updates a card by its ID.
Parameters:
id(String): The ID of the card to update.card(Object): The card object with updated data. Example:{ name: 'Updated Card', number: 5678 }
Returns:
- The updated card object.
Example:
const updatedCard = await sdk.updateCard('60d5f9b8f8d2e8b5b8f8b8f8', { name: 'Updated Card', number: 5678 });
console.log('Updated Card:', updatedCard);deleteCard(id)
Deletes a card by its ID.
Parameters:
id(String): The ID of the card to delete.
Returns:
- A success message.
Example:
const deleteResponse = await sdk.deleteCard('60d5f9b8f8d2e8b5b8f8b8f8');
console.log('Deleted Card:', deleteResponse);Error Handling
Each function throws an error if the request fails. You can catch these errors using a try-catch block:
try {
const newCard = await sdk.createCard({ name: 'Test Card', number: 1234 });
console.log('Created Card:', newCard);
} catch (error) {
console.error('Error:', error);
}License
ISC
