Skip to content

Commit

Permalink
readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Apr 2, 2024
1 parent ec43b5c commit 8bb8021
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions snapshotter/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Snapshot API

This is a Node.js application that provides an API endpoint for retrieving paginated, sorted, and filtered snapshot data.

## Installation

1. Clone the repository:
```

Check failure on line 8 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

snapshotter/server/README.md:8 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

Check failure on line 8 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should have a language specified [Context: " ```"]

snapshotter/server/README.md:8 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: " ```"]
git clone <repository-url>
```

2. Install the dependencies:
```

Check failure on line 13 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

snapshotter/server/README.md:13 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

Check failure on line 13 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should have a language specified [Context: " ```"]

snapshotter/server/README.md:13 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: " ```"]
npm i
```

3. Start the application:
```

Check failure on line 18 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

snapshotter/server/README.md:18 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

Check failure on line 18 in snapshotter/server/README.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should have a language specified [Context: " ```"]

snapshotter/server/README.md:18 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: " ```"]
npm start:local
```

## API Endpoint

The API endpoint is available at `/api/snapshot`.

### Query Parameters

The following query parameters can be used to customize the API response:

- `page` (optional, default: 0): Page number of the paginated results.
- `limit` (optional, default: 100): Maximum number of items per page.
- `sortBy` (optional, default: "name"): Field to sort the results by.
- Possible values: "name", "stake", "active_months", "vote_power", "stake_power", "activity_power"
- `sortOrder` (optional, default: "asc"): Order in which the results should be sorted.
- Possible values: "asc" (ascending), "desc" (descending)
- `prefix` (optional, default: ""): Prefix to filter the `account_id` field by.

### Example Requests

- `/api/snapshot`: First page of data with default sorting and no filtering.
- `/api/snapshot?page=1&limit=50`: Second page of data with 50 items per page.
- `/api/snapshot?sortBy=stake&sortOrder=desc`: First page of data sorted by stake in descending order.
- `/api/snapshot?page=2&limit=20&sortBy=vote_power&sortOrder=asc`: Third page of data sorted by vote power in ascending order with 20 items per page.
- `/api/snapshot?prefix=00&sortBy=activity_power&sortOrder=desc`: First page of data filtered by `account_id` prefix "00" and sorted by activity power in descending order.

### Error Handling

If an invalid `sortBy` parameter is provided, the API will respond with a 400 status code and an error message indicating the invalid parameter.

## Configuration

The application can be configured using the following environment variables:

- `SERVER_PORT` (default: 3000): The port on which the server will run.
- `SNAPSHOT_FILE` (default: 'snapshot.json'): The path to the snapshot JSON file.

0 comments on commit 8bb8021

Please sign in to comment.