Skip to content

Commit 8b8e9f4

Browse files
committed
Guide: move api intro to main guide
1 parent 6c26280 commit 8b8e9f4

File tree

7 files changed

+86
-91
lines changed

7 files changed

+86
-91
lines changed

content/docs/1_guide/20_api/1_introduction/guide.txt

-85
This file was deleted.

content/docs/1_guide/20_api/3_data/guide.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Title: Data
22

33
----
44

5-
Intro: Once you start (link: docs/guide/api/introduction#further-customize-the-api text: customizing the API) and adding your own API endpoints, there is a lot to know about how to interact with data in the callback functions.
5+
Intro: Once you start (link: docs/guide/api#further-customize-the-api text: customizing the API) and adding your own API endpoints, there is a lot to know about how to interact with data in the callback functions.
66

77
----
88

content/docs/1_guide/20_api/guide.txt

+81-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,84 @@ Category: Extending Kirby
1010

1111
----
1212

13-
Icon: cloud
13+
Intro: Kirby's REST API is used by the (glossary: Panel) to connect between the (glossary: Vue) frontend and the PHP backend. It offers full access to your site, pages, files, users and more. You can use it for your SPA or mobile applications built on top of Kirby.
14+
15+
----
16+
17+
Text:
18+
19+
## Endpoints
20+
There are a large number of endpoints, split into the following areas:
21+
22+
(reference: api)
23+
24+
## Authentication
25+
26+
Every API request requires authentication. We offer session-based authentication or HTTP Basic auth. (link: docs/guide/api/authentication text: Read more ›)
27+
28+
## Language
29+
In a (link: docs/guide/languages text: multi-language site) it is necessary to specify the language for which you want to use the API. This is done by sending an `X-Language` header containing the desired language code with your request.
30+
31+
## Errors
32+
33+
### Example error
34+
35+
```js
36+
{
37+
"status": "error",
38+
"message": "The page \"example\" cannot be found",
39+
"code": 404
40+
}
41+
```
42+
43+
### In debug mode
44+
45+
When debug mode is activated in your config, you will get a more detailed error response with the exception type, file and line.
46+
47+
```js
48+
{
49+
"status": "error",
50+
"exception": "Exception",
51+
"message": "The page \"example\" cannot be found",
52+
"file": "config/api/data.php",
53+
"line": 46,
54+
"code": 500
55+
}
56+
```
57+
58+
To activate the debug mode, add the following to your config:
59+
60+
```php "/site/config/config.php"
61+
return [
62+
'debug' => true
63+
];
64+
```
65+
66+
<warning>
67+
Please make sure to disable `debug` mode in production! Displaying PHP errors on a public server can be a serious security risk:
68+
69+
- Error messages are displayed with detailed information about the code structure (e.g. file path, class, method)
70+
- With Whoops enabled, there will be even more detailed information about the code structure
71+
- Detailed error messages for login failures could leak information to attackers
72+
73+
In a production environment, always log errors to your PHP error logs.
74+
</warning>
75+
76+
77+
## Custom API location
78+
79+
Kirby can be configured to host the API at a different location. This can be set up in your config.
80+
81+
```php "/site/config/config.php"
82+
return [
83+
'api' => [
84+
'slug' => 'rest'
85+
]
86+
];
87+
```
88+
89+
All API endpoints are now available at `https://yourdomain.com/rest`. The Panel will automatically switch to the new API location.
90+
91+
## Further customize the API
92+
93+
Find out how you can define custom endpoints, data functions, models etc. either via your (link: docs/reference/system/options/api text: config options ›) or (link: docs/reference/plugins/extensions/api text: in a plugin ›).

content/docs/1_guide/22_beyond-kirby/guide.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Using the REST API is the way to go if you want to modify data.
9494

9595
### Documentation
9696

97-
- (link: docs/guide/api/introduction text: Using the REST API)
97+
- (link: docs/guide/api text: Using the REST API)
9898
- (link: docs/guide/api/authentication text: REST API authentication method)
9999
- (link: docs/reference/api text: API endpoint reference)
100100
- (link: docs/reference/plugins/extensions/api text: Custom API endpoints and data providers)

content/docs/2_reference/7_plugins/1_extensions/0_api/reference-extension.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Kirby::plugin('my/api', [
3535

3636
Your new endpoint is now available at `https://yourdomain.com/api/my-endpoint` and will return a json encoded version of the returned array.
3737

38-
The endpoint is automatically protected with the same authentication layer as our own endpoints. It will also move when you (link: docs/guide/api/introduction#custom-api-location text: change the API slug).
38+
The endpoint is automatically protected with the same authentication layer as our own endpoints. It will also move when you (link: docs/guide/api#custom-api-location text: change the API slug).
3939

4040
### Access to `$kirby`
4141

content/docs/2_reference/7_plugins/1_extensions/0_fields/reference-extension.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Text:
1414

1515
## What makes a field plugin?
1616

17-
Our Kirby panel is built with (glossary: vue) and speaks to our (link: docs/guide/api/introduction text: REST API). Your field plugin needs to consist out of **three parts**:
17+
Our Kirby panel is built with (glossary: vue) and speaks to our (link: docs/guide/api text: REST API). Your field plugin needs to consist out of **three parts**:
1818

1919
- PHP code for the REST API: `index.php`
2020
- Vue code for the panel: `index.js`

content/releases/3-0/default.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ We've overhauled our entire plugin system and built a more reliable and consiste
7676

7777
Kirby 3 has a built in REST API. You can comfortably create and edit your content in the Panel, and then consume your content in SPAs, mobile applications or static site generators.
7878

79-
(link: docs/guide/api/introduction text: Learn more ›)
79+
(link: docs/guide/api text: Learn more ›)
8080

8181
## Virtual pages & external data sources
8282

0 commit comments

Comments
 (0)