Skip to content

Commit

Permalink
docs: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Feb 27, 2024
1 parent 4ecc650 commit d9c402c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
45 changes: 4 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,50 +89,13 @@ yarn add pawnote
npm install pawnote
```

## Usage
## Documentation & Guides

You can see multiple examples in the [`examples`](./examples) folder.
You can find the documentation, some guides and small examples at [pawnote.js.org](https://pawnote.js.org) for more informations about the API and how to use it.

### Tauri
If you need complete examples, then we got **a lot** of those in the [`examples`](./examples) folder, hoping you can find your joy in there.

Since Pawnote uses `fetch` as default fetcher, you need to use a custom fetcher to make it work with the [Tauri HTTP API](https://tauri.app/v1/api/js/http).

Here's an example fetcher made to work with Tauri (v1) :

```typescript
import { type PawnoteFetcher } from "pawnote";
import { Body, ResponseType, getClient } from "@tauri-apps/api/http";

const tauriPawnoteFetcher: PawnoteFetcher = async (url, options) => {
const client = await getClient(options.redirect === "manual" ? {
maxRedirections: 0
} : void 0);

const response = await client.request<string>({
url,
method: options.method,
headers: options.headers,
body: options.method !== "GET" && options.body ? Body.text(options.body) : void 0,
responseType: ResponseType.Text
});

return {
headers: response.headers,
text: async () => response.data,
json: async <T>() => JSON.parse(response.data) as T
}
};

export default tauriPawnoteFetcher;
```

## API

Documentation is not yet available, for now you'll have to use intellisense.
Most of the methods are self-explanatory and well commented.

We'll see if we can generate a documentation website
using comments from the source code in the future.
If none of those are helpful, you can always [open an issue](https://github.com/LiterateInk/Pawnote/issues) to ask for help.

## Resources

Expand Down
37 changes: 37 additions & 0 deletions docs/src/content/docs/guides/tauri.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Tauri
description: Want to make Pawnote run under Tauri ? Here's how to do it.
---

## Fetcher (for Tauri v1)

Since Pawnote uses [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) as default fetcher, you need to create a custom fetcher to make it work with the [Tauri HTTP API](https://tauri.app/v1/api/js/http).

Here's a simple one that should always work for Pawnote:

```typescript
import { type PawnoteFetcher } from "pawnote";
import { Body, ResponseType, getClient } from "@tauri-apps/api/http";

const tauriPawnoteFetcher: PawnoteFetcher = async (url, options) => {
const client = await getClient(options.redirect === "manual" ? {
maxRedirections: 0
} : void 0);

const response = await client.request<string>({
url,
method: options.method,
headers: options.headers,
body: options.method !== "GET" && options.body ? Body.text(options.body) : void 0,
responseType: ResponseType.Text
});

return {
headers: response.headers,
text: async () => response.data,
json: async <T>() => JSON.parse(response.data) as T
}
};

export default tauriPawnoteFetcher;
```

0 comments on commit d9c402c

Please sign in to comment.