forked from pocketnetteam/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: adding proxy API documentetation and slightly updating some par…
…ts of it. Also, removing redundant Appendix from the user center
- Loading branch information
Showing
5 changed files
with
1,121 additions
and
3,036 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,324 @@ | ||
# Getting Started | ||
# Get Started | ||
|
||
# Bastyon Pocketnet Proxy API Documentation | ||
|
||
## Overview | ||
The Bastyon Pocketnet Proxy API provides developers with tools to build and integrate applications within the Bastyon ecosystem. This guide explains how to use our RPC methods safely and efficiently with TypeScript support. | ||
|
||
The setup instructions assume you have a front-end that will invoke back-end controllers, defined below. | ||
|
||
The high-level diagram of a generic app looks something like the below: | ||
|
||
<div style="text-align: center;"> | ||
<img src="../assets/images/mini-app-flow.png" alt="mini-app-flow"> | ||
</div> | ||
|
||
## Setup and Initialization | ||
|
||
Until the proxy API is available via npm, we recommend using our template project: [Bastyon Mini-App Express.js Template][template-link]. | ||
|
||
The following instructions assume you have installed the /lib folder containing the pocketnet-proxy-api SDK. | ||
|
||
What this means: You'll need to clone our template repository first, as it contains all necessary files and configurations to get started quickly. | ||
|
||
[template-link]: https://github.com/DaniilKimlb/bastyon-miniapp-expressjs-template | ||
|
||
```typescript | ||
import express from 'express'; | ||
import type { Request, Response } from 'express'; | ||
import { PocketNetProxyApi } from '../lib'; | ||
import type { | ||
GetNodeInfoParams, | ||
GetUserProfileParams, | ||
SearchParams | ||
} from '../lib/rpc.types'; | ||
|
||
const app = express(); | ||
``` | ||
|
||
## API Instance Management | ||
What this means: We use a singleton pattern to manage a single instance of the API throughout your application. This approach is more efficient and prevents multiple unnecessary connections. | ||
|
||
```typescript | ||
// lib/index.ts | ||
import PocketNetProxyApi from './pocketnet-proxy-api'; | ||
|
||
let pocketNetProxyInstance: PocketNetProxyApi | null = null; | ||
|
||
export async function getPocketNetProxyInstance(): Promise<PocketNetProxyApi> { | ||
if (!pocketNetProxyInstance) { | ||
pocketNetProxyInstance = await PocketNetProxyApi.create(); | ||
} | ||
return pocketNetProxyInstance; | ||
} | ||
|
||
export { PocketNetProxyApi }; | ||
``` | ||
|
||
## Route Handlers | ||
What this means: These are the endpoints your application will expose to handle different types of requests. Each handler is responsible for a specific function like getting node information or user profiles. | ||
|
||
### Get Node Information | ||
What this means: This endpoint fetches current status and information about a Bastyon network node, useful for monitoring and diagnostics. | ||
|
||
```typescript | ||
// controllers/node.controller.ts | ||
import type { Request, Response } from 'express'; | ||
import { getPocketNetProxyInstance } from '../lib'; | ||
|
||
/** | ||
* GET /nodeinfo | ||
* | ||
* Retrieves node information from the Bastyon network. | ||
* Uses the getnodeinfo RPC method to fetch current node status. | ||
* | ||
* @param {Request} req - Express request object | ||
* @param {Response} res - Express response object | ||
* @returns {Promise<void>} JSON response with node information | ||
* | ||
* @example | ||
* // Route registration | ||
* app.get('/nodeinfo', getNodeInfo); | ||
* | ||
* // Success Response | ||
* { | ||
* "message": "Node information retrieved successfully", | ||
* "data": { | ||
* // Node information object | ||
* } | ||
* } | ||
*/ | ||
export async function getNodeInfo( | ||
req: Request, | ||
res: Response | ||
): Promise<void> { | ||
try { | ||
const api = await getPocketNetProxyInstance(); | ||
const result = await api.rpc.getnodeinfo(); | ||
|
||
res.status(200).json({ | ||
message: 'Node information retrieved successfully', | ||
data: result | ||
}); | ||
} catch (error) { | ||
res.status(500).json({ | ||
message: 'Failed to retrieve node information', | ||
error: error instanceof Error ? error.message : 'Unknown error' | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
### Get User Profile | ||
What this means: This endpoint retrieves information about a specific user using their blockchain address. It's commonly used for displaying user details and verification. | ||
|
||
```typescript | ||
// controllers/user.controller.ts | ||
import type { Request, Response } from 'express'; | ||
import { getPocketNetProxyInstance } from '../lib'; | ||
import type { GetUserProfileParams } from '../lib/rpc.types'; | ||
|
||
/** | ||
* GET /user/:address | ||
* | ||
* Retrieves user profile information for a given address. | ||
* | ||
* @param {Request} req - Express request object with address parameter | ||
* @param {Response} res - Express response object | ||
* @returns {Promise<void>} JSON response with user profile | ||
* | ||
* @example | ||
* // Route registration | ||
* app.get('/user/:address', getUserProfile); | ||
* | ||
* // Success Response | ||
* { | ||
* "message": "User profile retrieved successfully", | ||
* "data": { | ||
* // User profile object | ||
* } | ||
* } | ||
*/ | ||
export async function getUserProfile( | ||
req: Request, | ||
res: Response | ||
): Promise<void> { | ||
try { | ||
const { address } = req.params; | ||
const api = await getPocketNetProxyInstance(); | ||
|
||
const result = await api.rpc.getuserprofile({ | ||
address, | ||
shortForm: "basic" | ||
} satisfies GetUserProfileParams); | ||
|
||
res.status(200).json({ | ||
message: 'User profile retrieved successfully', | ||
data: result | ||
}); | ||
} catch (error) { | ||
res.status(500).json({ | ||
message: 'Failed to retrieve user profile', | ||
error: error instanceof Error ? error.message : 'Unknown error' | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
### Search Content | ||
What this means: This endpoint allows users to search through content on the platform with support for pagination to handle large result sets efficiently. | ||
|
||
```typescript | ||
// controllers/search.controller.ts | ||
import type { Request, Response } from 'express'; | ||
import { getPocketNetProxyInstance } from '../lib'; | ||
import type { SearchParams } from '../lib/rpc.types'; | ||
|
||
/** | ||
* GET /search | ||
* | ||
* Searches for content with pagination support. | ||
* | ||
* @param {Request} req - Express request object with query parameters | ||
* @param {Response} res - Express response object | ||
* @returns {Promise<void>} JSON response with search results | ||
* | ||
* @example | ||
* // Route registration | ||
* app.get('/search', searchContent); | ||
* | ||
* // Request | ||
* GET /search?keyword=blockchain&page=1&pageSize=20 | ||
* | ||
* // Success Response | ||
* { | ||
* "message": "Search completed successfully", | ||
* "data": { | ||
* "results": [], | ||
* "total": 0 | ||
* } | ||
* } | ||
*/ | ||
export async function searchContent( | ||
req: Request, | ||
res: Response | ||
): Promise<void> { | ||
try { | ||
const { | ||
keyword, | ||
page = '0', | ||
pageSize = '20' | ||
} = req.query; | ||
|
||
const api = await getPocketNetProxyInstance(); | ||
|
||
const result = await api.rpc.search({ | ||
keyword: String(keyword), | ||
type: "content", | ||
pageStart: Number(page), | ||
pageSize: Number(pageSize) | ||
} satisfies SearchParams); | ||
|
||
res.status(200).json({ | ||
message: 'Search completed successfully', | ||
data: result | ||
}); | ||
} catch (error) { | ||
res.status(500).json({ | ||
message: 'Search operation failed', | ||
error: error instanceof Error ? error.message : 'Unknown error' | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
### Controller Exports | ||
What this means: This file centralizes all your route handlers (controllers) in one place for better organization and maintainability. | ||
|
||
```typescript | ||
// controllers/index.ts | ||
export * from './node.controller'; | ||
export * from './user.controller'; | ||
export * from './search.controller'; | ||
``` | ||
|
||
### Route Registration | ||
What this means: This is where you define which URLs trigger which handlers in your application. It maps URLs to their corresponding functions. | ||
|
||
```typescript | ||
// routes/index.ts | ||
import express from 'express'; | ||
import { | ||
getNodeInfo, | ||
getUserProfile, | ||
searchContent | ||
} from '../controllers'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/nodeinfo', getNodeInfo); | ||
router.get('/user/:address', getUserProfile); | ||
router.get('/search', searchContent); | ||
|
||
export default router; | ||
``` | ||
|
||
### Error Handler Middleware | ||
What this means: This middleware catches and processes any errors that occur during request handling, ensuring a consistent error response format. | ||
|
||
```typescript | ||
// middleware/error.middleware.ts | ||
import type { Request, Response, NextFunction } from 'express'; | ||
|
||
export function errorHandler( | ||
error: Error, | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
): void { | ||
console.error('API Error:', error); | ||
|
||
res.status(500).json({ | ||
message: 'Internal server error', | ||
error: process.env.NODE_ENV === 'development' ? error.message : 'Unknown error' | ||
}); | ||
} | ||
``` | ||
|
||
## App Configuration | ||
What this means: This is the main setup of your Express.js application where you configure middleware, routes, and error handling. | ||
|
||
```typescript | ||
// app.ts | ||
import express from 'express'; | ||
import routes from './routes'; | ||
import { errorHandler } from './middleware'; | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
app.use('/api', routes); | ||
app.use(errorHandler); | ||
|
||
export default app; | ||
``` | ||
|
||
## Best Practices | ||
These guidelines will help you build more reliable and maintainable applications: | ||
|
||
1. TypeScript Usage: Leverage TypeScript's type system for safer code | ||
2. Parameter Validation: Use the `satisfies` operator to ensure correct parameter types | ||
3. Error Handling: Implement comprehensive error catching and reporting | ||
4. Service Organization: Group related functionality into service classes | ||
5. Data Management: Use pagination for large datasets | ||
6. Performance: Implement caching where appropriate | ||
7. Code Structure: Keep your code organized and well-documented | ||
|
||
## Type Safety Benefits | ||
Using TypeScript provides several advantages: | ||
|
||
- Find errors during development instead of runtime | ||
- Get better code completion in your IDE | ||
- Make your code easier to understand and maintain | ||
- Ensure consistent data structures | ||
- Improve development speed with better tooling support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,67 @@ | ||
# Introduction | ||
# Introduction | ||
|
||
# Bastyon Pocketnet Proxy API Documentation | ||
|
||
## Introduction | ||
|
||
The Bastyon Pocketnet Proxy API serves as a powerful gateway for developers to build and integrate applications within the Bastyon ecosystem. This comprehensive API enables developers to harness the full potential of Bastyon's decentralized platform, providing access to core functionalities such as user management, content distribution, blockchain operations, and social networking features. | ||
|
||
### What is Bastyon Pocketnet Proxy? | ||
|
||
Bastyon's Pocketnet Proxy is a middleware layer that facilitates seamless communication between applications and the Bastyon blockchain network. It provides a standardized interface for developers to interact with the platform's features while abstracting the complexity of direct blockchain interactions. | ||
|
||
### Key Features | ||
|
||
- **User Management**: Complete suite of methods for handling user profiles, authentication, and account management | ||
- **Content Management**: Tools for creating, retrieving, and managing content across the platform | ||
- **Social Networking**: APIs for handling user interactions, subscriptions, and social connections | ||
- **Blockchain Operations**: Direct access to blockchain functionalities including transactions and block data | ||
- **Search and Discovery**: Comprehensive search capabilities across various platform elements | ||
- **Jury System**: Methods for managing the platform's decentralized moderation system | ||
|
||
### API Design Principles | ||
|
||
The API follows these core principles: | ||
|
||
1. **Consistency**: All methods follow a standardized naming convention and response format | ||
2. **Scalability**: Built-in pagination and efficient data handling for large-scale operations | ||
3. **Security**: Robust authentication and authorization mechanisms | ||
4. **Flexibility**: Support for various use cases and integration scenarios | ||
|
||
### Getting Started | ||
|
||
This documentation provides a complete reference of all available API methods, including: | ||
|
||
- Detailed method definitions and parameters | ||
- Working code examples for each method | ||
- Common usage patterns and best practices | ||
- Error handling guidelines | ||
- Response format specifications | ||
|
||
### Who Should Use This API? | ||
|
||
- Application developers building on the Bastyon platform | ||
- Integration developers connecting existing systems with Bastyon | ||
- Content creators looking to automate their workflow | ||
- Developers building tools for the Bastyon ecosystem | ||
|
||
### Prerequisites | ||
|
||
Before using the API, you should have: | ||
|
||
- Basic understanding of REST APIs and JSON | ||
- Familiarity with blockchain concepts | ||
- Knowledge of TypeScript/JavaScript (for provided examples) | ||
- Access credentials for the Bastyon platform | ||
|
||
### How to Use This Documentation | ||
|
||
The documentation is organized into logical sections based on functionality: | ||
|
||
1. **Method Reference**: Complete list of all available API methods | ||
2. **Usage Examples**: Real-world examples of API implementation | ||
3. **Best Practices**: Guidelines for optimal API usage | ||
4. **Error Handling**: Common error scenarios and how to handle them | ||
5. **Advanced Topics**: Complex implementation patterns and optimizations | ||
|
||
Let's begin exploring the comprehensive set of API methods available for building powerful applications on the Bastyon platform. |
Oops, something went wrong.