Skip to content

Commit

Permalink
Merge pull request #46 from benwest/patch-1
Browse files Browse the repository at this point in the history
Don't use ohmyfetch in docs
  • Loading branch information
lukasbestle authored Mar 25, 2023
2 parents 42e32cb + eb597b9 commit 1071799
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,36 @@ return [

### Sending POST Requests

You can use any HTTP request library in your language of choice to make regular POST requests to your `/api/query` endpoint. In this example, we are using [ohmyfetch](https://github.com/unjs/ohmyfetch) (a better fetch API for Node and the browser) and JavaScript to retreive data from our Kirby installation.
You can use any HTTP request library in your language of choice to make regular POST requests to your `/api/query` endpoint. In this example, we are using [the `fetch` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and JavaScript to retrieve data from our Kirby installation.

```js
import { $fetch } from "ohmyfetch";

const api = "https://yoursite.com/api/query";
const username = "apiuser";
const password = "strong-secret-api-password";

const headers = {
Authorization: Buffer.from(`${username}:${password}`).toString("base64"),
Authorization: "Basic " + Buffer.from(`${username}:${password}`).toString("base64"),
"Content-Type": "application/json",
Accept: "application/json",
};

const response = await $fetch(api, {
const response = await fetch(api, {
method: "post",
body: {
body: JSON.stringify({
query: "page('notes').children",
select: {
title: true,
text: "page.text.kirbytext",
slug: true,
date: "page.date.toDate('d.m.Y')",
},
},
}),
headers,
});

console.log(response);
const json = await response.json();

console.log(json);
```

### `query`
Expand Down

0 comments on commit 1071799

Please sign in to comment.