stacks-client
v1.2.1
Published
This library provides a set of tools for interacting with various services, including pipelines, OAuth, and generic APIs. It is designed to simplify the process of making HTTP requests and handling responses in your JavaScript or TypeScript projects.
Downloads
5
Readme
Stacks Library Documentation
Welcome to the documentation for the Stacks library! This library provides a set of tools for interacting with various services, including pipelines, OAuth, and generic APIs. It is designed to simplify the process of making HTTP requests and handling responses in your JavaScript or TypeScript projects.
Installation
To install the Stacks library, you can use npm or yarn:
npm install stacks-client
# or
yarn add stacks-client
Usage
1. Configuration
Before using any of the library functionalities, you need to set the configuration with your application credentials. Use the setConfig
function provided by the library:
import { setConfig } from 'stacks-client';
setConfig('YourAppName', 'YourAppSecret', 'YourApiId');
2. Pipeline
The Pipeline
class allows you to interact with pipelines. You can run or stop a pipeline with the specified ID.
import { Pipeline } from 'stacks-client';
const pipeline = new Pipeline();
// Run a pipeline
pipeline.run('pipelineId')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
// Stop a pipeline
pipeline.stop('pipelineId')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
3. OAuth
The OAuth
class provides functionalities for OAuth authentication. You can log in, get user information, and register new users.
import { OAuth } from 'stacks-client';
const oauth = new OAuth();
// Login
oauth.login('[email protected]', 'password')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
// Get user information
oauth.get('userId')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
// Register new user
oauth.register('[email protected]', 'password')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
4. Generic API
The API
class allows you to make generic HTTP requests to any endpoint.
import { API } from 'stacks-client';
const api = new API();
// Make a GET request
api.get('https://api.example.com/data')
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
// Make a POST request
api.post('https://api.example.com/post', { data: 'example' })
.then(response => {
// Handle response
})
.catch(error => {
// Handle error
});
Response Structure
The response data structure returned by the library functions follows the format defined by the MyResponse
interface:
interface MyResponse {
status: string;
data: any; // Actual response data from the API
}
You can access the response status and data from the returned Promise.