Skip to content

Commit

Permalink
docs: update markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
aliosmandev committed Feb 24, 2024
1 parent e92b8db commit e12aa09
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
62 changes: 48 additions & 14 deletions apps/docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,45 @@ To start using `@postiva/client` in your project, follow these steps:

::code-group
<!-- prettier-ignore -->
```bash [Npm]
```bash [npm]
npm install @postiva/js
```
<!-- prettier-ignore -->
```bash [Yarn]
```bash [yarn]
yarn add @postiva/js
```
<!-- prettier-ignore -->
```bash [Pnpm]
```bash [pnpm]
pnpm add @postiva/js
```
::

Next, initialize the Postiva Client in your application by providing your workspace ID and API key:

::code-group
<!-- prettier-ignore -->
```javascript[libs/postiva.ts]
const { PostivaClient } = require('@postiva/client');
```javascript[libs/postiva.js]
const { createClient } = require('@postiva/client');
const client = createClient('yourWorkspaceId', 'yourApiKey');
```
```typescript[libs/postiva.ts]
import { createClient } from '@postiva/client'
const client = new PostivaClient('yourWorkspaceId', 'yourApiKey');
const client = createClient('yourWorkspaceId', 'yourApiKey');
```
::

## Usage

Here's a simple example to fetch content using the Postiva Client:

### Fetch the contents

::code-group
<!-- prettier-ignore -->
```javascript[pages/index.tsx]
async function fetchContents() {
```javascript[getContents]
async function getContents() {
try {
const contents = await client.getContents();
console.log(contents);
Expand All @@ -69,8 +77,39 @@ async function fetchContents() {
}
}
fetchContents();
getContentsWithQuery();
```
<!-- prettier-ignore -->
```javascript[getContentsWithQuery]
import { GetContentsType } from '@postiva/client'
async function getContentsWithQuery({ query, type, category }: GetContentsType) {
try {
const contents = await client.getContents({ query, type, category });
console.log(contents);
} catch (error) {
console.error('Error fetching contents:', error);
}
}
getContentsWithQuery();
```
<!-- prettier-ignore -->
```javascript[getContentsWithPagination]
import { GetContentsType } from '@postiva/client'
async function getContentsWithPagination({ page, size }: IPaginatinoOptions) {
try {
const contents = await client.getContents().pagination({ page, size })
console.log(contents);
} catch (error) {
console.error('Error fetching contents:', error);
}
}
getContentsWithPagination();
```
::

### Fetch the content detail

Expand Down Expand Up @@ -123,11 +162,6 @@ const client = new PostivaClient('yourWorkspaceId');

A secure key used for API authentication.

<!-- prettier-ignore -->
```typescript[libs/postiva.ts]
const client = new PostivaClient('yourWorkspaceId', 'apiKey');
```

## Contributing

You're welcome to contribute to this module!
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { postivaClient } from "@/libs/postiva";

export default async function Home() {
const posts = await postivaClient.getContents({query: "test"}).pagination({page: 1, size: 1})
const posts = await postivaClient.getContents({query: "selam"}).pagination({page: 1, size: 1})

return (
<div>
Expand Down
10 changes: 6 additions & 4 deletions packages/library/src/libs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export interface PaginationResponse<T> {
pagination?: IPagination;
}

export interface IPaginatinoOptions {
page: number;
size: number;
}

export interface PaginatableResponse<T> {
pagination: ({
page,
size,
}: {
page: number;
size: number;
}) => Promise<PaginationResponse<T[]>>;
}: IPaginatinoOptions) => Promise<PaginationResponse<T[]>>;
}

export type ContentsResponse<T> = Promise<T[]> & PaginatableResponse<T>;
Expand Down

0 comments on commit e12aa09

Please sign in to comment.