Skip to content

Commit 95b2fd9

Browse files
committed
update features
Signed-off-by: bidi <[email protected]>
1 parent f02c59a commit 95b2fd9

File tree

8 files changed

+62
-78
lines changed

8 files changed

+62
-78
lines changed

docs/book/v5/core-features/content-validation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Content Negotiation
22

3+
> Introduced in Dotkernel API 4.5.0
4+
35
**Content Negotiation** is performed by an application in order :
46

57
- To match the requested representation as specified by the client via the Accept header with a representation the
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# Dependency Injection
22

3-
Dependency injection is a design pattern used in software development to implement inversion of control. In simpler
4-
terms, it's the act of providing dependencies for an object during instantiation.
3+
> Introduced in Dotkernel API 5.0.0
54
6-
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter
7-
injection and property injection.
5+
Dependency injection is a design pattern used in software development to implement inversion of control.
6+
In simpler terms, it's the act of providing dependencies for an object during instantiation.
87

9-
Dotkernel API, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package
10-
focuses only on constructor injection.
8+
In PHP, dependency injection can be implemented in various ways, including through constructor injection, setter injection and property injection.
9+
10+
Dotkernel API, through its [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package focuses only on constructor injection.
1111

1212
## Usage
1313

14-
**Dotkernel API** comes out of the box with the
15-
[dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package, which provides all we need for
16-
injecting dependencies into any object you want.
14+
**Dotkernel API** comes out of the box with the [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection) package, which provides all we need for injecting dependencies into any object you want.
1715

18-
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor
19-
of a class. Dependencies are specified as separate parameters of the `#[Inject]` attribute.
16+
`dot-dependency-injection` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor of a class.
17+
Dependencies are specified as separate parameters of the `#[Inject]` attribute.
2018

2119
For our example we will inject `UserService` and `config` dependencies into a `UseHandler`.
2220

@@ -37,11 +35,9 @@ class UserHandler implements RequestHandlerInterface
3735
}
3836
```
3937

40-
> If your class needs the value of a specific configuration key, you can specify the path using dot notation:
41-
> `config.example`
38+
> If your class needs the value of a specific configuration key, you can specify the path using dot notation `config.example`.
4239
43-
The next step is to register the class in the `ConfigProvider` under `factories` using
44-
`Dot\DependencyInjection\Factory\AttributedServiceFactory::class`
40+
The next step is to register the class in the `ConfigProvider` under `factories` using `Dot\DependencyInjection\Factory\AttributedServiceFactory::class`
4541

4642
```php
4743
public function getDependencies(): array
@@ -54,8 +50,8 @@ public function getDependencies(): array
5450
}
5551
```
5652

57-
That's it. When your object is instantiated from the container, it will automatically have its
58-
dependencies resolved.
53+
That's it.
54+
When your object is instantiated from the container, it will automatically have its dependencies resolved.
5955

60-
> Dependencies injection is available to any object within Dotkernel API. For example, you can inject dependencies in a
61-
> service, a handler and so on, simply by registering it in the `ConfigProvider`.
56+
> Dependencies injection is available to any object within Dotkernel API.
57+
> For example, you can inject dependencies in a service, a handler and so on, simply by registering it in the `ConfigProvider`.

docs/book/v5/core-features/error-reporting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Error reporting endpoint
22

3+
> Backward incompatibility introduced in Dotkernel API 4.1.0
4+
35
The error reporting endpoint was designed to allow the **frontend developers** of your API to report any bugs they encounter in a secure way that is fully under your control.
46
To prevent unauthorized usage, the endpoint is protected by a token in the request's header.
57

docs/book/v5/core-features/exceptions.md

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,50 @@
22

33
## What are exceptions?
44

5-
Exceptions are a powerful mechanism for handling errors and other exceptional conditions that may occur during the
6-
execution of a script.
7-
They provide a way to manage errors in a structured and controlled manner, separating error-handling code from regular
8-
code.
5+
Exceptions are a powerful mechanism for handling errors and other exceptional conditions that may occur during the execution of a script.
6+
They provide a way to manage errors in a structured and controlled manner, separating error-handling code from regular code.
97

10-
## How we use exceptions?
8+
## How we use exceptions
119

12-
When it comes to handling exceptions, **Dotkernel API** relies on the usage of easy-to-understand, problem-specific
13-
exceptions.
14-
15-
Out-of-the-box we provide the following custom exceptions:
10+
When it comes to handling exceptions, **Dotkernel API** relies on the usage of easy-to-understand, problem-specific exceptions.
11+
Below we will list the available custom exceptions.
1612

1713
### `BadRequestException` thrown when
1814

19-
* client tries to create/update resource, but the data from the request is invalid/incomplete (example: client tries to
20-
create an account, but does not send the required `identity` field)
15+
* The Client tries to **create/update resource**, but the **request data is invalid/incomplete** (example: client tries to create an account, but does not send the required `identity` field)
2116

2217
### `ConflictException` thrown when
2318

24-
* resource cannot be created because a different resource with the same identifier already exists (example: cannot
25-
change existing user's identity because another user with the same identity already exists)
26-
* resource cannot change its state because it is already in the specified state (example: user cannot be activated
27-
because it is already active)
19+
* The **resource cannot be created** because a different resource with the same identifier **already exists** (example: cannot change existing user's identity because another user with the same identity already exists)
20+
* The **resource cannot change its state** because it is **already in the specified state** (example: user cannot be activated because it is already active)
2821

2922
### `ExpiredException` thrown when
3023

31-
* resource cannot be accessed because it expired (example: account activation link)
32-
* resource cannot be accessed because it has been consumed (example: one-time password)
24+
* The **resource cannot be accessed**
25+
* because it has **expired** (example: account activation link)
26+
* because it has been **consumed** (example: one-time password)
3327

3428
### `ForbiddenException` thrown when
3529

36-
* resource cannot be accessed by the authenticated client (example: client authenticated as regular user sends
37-
a `GET /admin` request)
30+
* The **resource cannot be accessed** by the authenticated client's **role** (example: client authenticated as regular user sends a `GET /admin` request)
3831

3932
### `MethodNotAllowedException` thrown when
4033

41-
* client tries to interact with a resource via an invalid HTTP request method (example: client sends a `PATCH /avatar`
42-
request)
34+
* The client tries to interact with a resource via an **invalid HTTP request method** (example: client sends a `PATCH /avatar` request)
4335

4436
### `NotFoundException` thrown when
4537

46-
* client tries to interact with a resource that does not exist on the server (example: client sends
47-
a `GET /resource-does-not-exist` request)
38+
* The client tries to interact with a **resource that does not exist** on the server (example: client sends a `GET /resource-does-not-exist` request)
4839

4940
### `UnauthorizedException` thrown when
5041

51-
* resource cannot be accessed because the client is not authenticated (example: unauthenticated client sends
52-
a `GET /admin` request)
42+
* The **resource cannot be accessed** because the **client is not authenticated** (example: unauthenticated client sends a `GET /admin` request)
5343

54-
## How it works?
44+
## How it works
5545

56-
During a request, if there is no uncaught exception **Dotkernel API** will return a JSON response with the data provided
57-
by the handler that handled the request.
46+
During a request, if there is no uncaught exception, **Dotkernel API** will return a JSON response with the data provided by the handler that processed the request.
5847

59-
Else, it will build and send a response based on the exception thrown:
48+
Otherwise, it will build and send a response based on the exception thrown:
6049

6150
* `BadRequestException` will return a `400 Bad Request` response
6251
* `UnauthorizedException` will return a `401 Unauthorized` response
@@ -67,11 +56,12 @@ Else, it will build and send a response based on the exception thrown:
6756
* `ExpiredException` will return a `410 Gone` response
6857
* `MailException`, `RuntimeException` and the generic `Exception` will return a `500 Internal Server Error` response
6958

70-
## How to extend?
59+
## How to extend
7160

72-
In this example we will create a custom exception called `CustomException`, place it next to the already existing custom
73-
exceptions (you can use your preferred location) and finally return a custom HTTP status code when `CustomException` is
74-
encountered.
61+
In this example we will
62+
* Create a custom exception called `CustomException`
63+
* Place it next to the already existing custom exceptions (you can use your preferred location)
64+
* Return a custom HTTP status code when `CustomException` is encountered.
7565

7666
### Step 1: Create exception file
7767

@@ -106,8 +96,7 @@ Save and close the file.
10696

10797
### Step 3: Test for failure
10898

109-
Access your API's home page URL and make sure it returns `500 Internal Server Error` HTTP status code and the following
110-
content:
99+
Access your API's home page URL and make sure it returns `500 Internal Server Error` HTTP status code and the following content:
111100

112101
```json
113102
{
@@ -133,5 +122,5 @@ Save and close the file.
133122

134123
### Step 5: Test for success
135124

136-
Again, access your API's home page URL, which should return the same content.
125+
Access your API's home page URL, which should return the same content.
137126
Notice that this time it returns `418 I'm a teapot` HTTP status code.

docs/book/v5/tutorials/api-evolution.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# API Evolution pattern
22

3-
API evolution: Updating an API while keeping it compatible for existing consumers by adding new features, fixing bugs,
4-
planning and removing outdated features.
3+
API evolution: Updating an API while keeping it compatible for existing consumers by adding new features, fixing bugs, planning and removing outdated features.
54

65
## How it works
76

@@ -13,10 +12,10 @@ We use response headers to inform the consumers about the future changes by usin
1312

1413
**Both headers are independent, you can use them separately.**
1514

16-
> Make sure you have the `DeprecationMiddleware:class` piped in your `pipeline` list. In our case it's
17-
> `config/pipeline.php`.
15+
> Make sure you have the `DeprecationMiddleware:class` piped in your `pipeline` list.
16+
> In our case it's `config/pipeline.php`.
1817
19-
### Marking an entire endpoint as deprecated
18+
## Marking an entire endpoint as deprecated
2019

2120
When you want to mark an entire resource as deprecated you have to use the `ResourceDeprecation` attribute.
2221

@@ -34,8 +33,7 @@ class HomeHandler implements RequestHandlerInterface
3433
...
3534
```
3635

37-
In the example above, the ``ResourceDeprecation`` attribute is attached to the class, marking the entire `/` (home)
38-
endpoint as deprecated starting from `2038-01-01`.
36+
In the example above, the `ResourceDeprecation` attribute is attached to the class, marking the entire `/` (home) endpoint as deprecated starting from `2038-01-01`.
3937

4038
Running the following curl will print out the response headers where we can see the **Sunset** and **Link** headers.
4139

@@ -56,10 +54,9 @@ Link: https://docs.dotkernel.org/api-documentation/v5/core-features/versioning;r
5654
Vary: Origin
5755
```
5856

59-
### Marking a method as deprecated
57+
## Marking a method as deprecated
6058

61-
Most of the time you want to deprecate only an endpoint, so you will need to use the `MethodDeprecation` attribute which
62-
has the same parameters, but it attaches to a handler method.
59+
Most of the time you want to deprecate only an endpoint, so you will need to use the `MethodDeprecation` attribute which has the same parameters, but it attaches to a handler method.
6360

6461
```php
6562
...
@@ -90,6 +87,8 @@ If you followed along you can run the below curl:
9087
curl --head -X GET http://0.0.0.0:8080 -H "Content-Type: application/json"
9188
```
9289

90+
The response lists the **Sunset** and **Link** headers.
91+
9392
```shell
9493
HTTP/1.1 200 OK
9594
Host: 0.0.0.0:8080
@@ -103,7 +102,7 @@ Link: https://docs.dotkernel.org/api-documentation/v5/core-features/versioning;r
103102
Vary: Origin
104103
```
105104

106-
### NOTES
105+
## NOTES
107106

108107
> If `Link` or `Sunset` do not have a value they will not appear in the response headers.
109108
@@ -113,5 +112,4 @@ Vary: Origin
113112
114113
> Deprecations can only be attached to handler classes that implement `RequestHandlerInterface`.
115114
116-
> The `rel` and `type` arguments are optional, they default to `sunset` and `text/html` if no value was provided and
117-
> are `Link` related parts.
115+
> The `rel` and `type` arguments are optional, they default to `sunset` and `text/html` if no value was provided and are `Link` related parts.
File renamed without changes.

docs/book/v5/upgrading.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# Upgrades
22

33
Dotkernel API does not provide an automatic upgrade path.
4-
54
Instead, the recommended procedure is to manually implement each modification listed in [releases](https://github.com/dotkernel/api/releases).
6-
Additionally, releases info can also be accessed as an [RSS](https://github.com/dotkernel/api/releases.atom) feed.
5+
Additionally, release info can also be accessed as an [RSS](https://github.com/dotkernel/api/releases.atom) feed.
76

87
## Upgrade procedure
98

109
Once you clone Dotkernel API, you will find a [CHANGELOG.md](https://github.com/dotkernel/api/blob/5.0/CHANGELOG.md) file in the root of the project.
10+
This file contains a list of already implemented features in reverse chronological order.
11+
You can use this file to track the version of your copy of Dotkernel API.
1112

12-
This contains a list of already implemented features in reversed chronological order.
13-
You can use this file to track the version your copy of Dotkernel API is at.
14-
15-
When there is a new release, you need to run through it and implement in your project the modifications from each pull request.
16-
17-
Finally, copy the release info and paste it at the beginning of your project's CHANGELOG.md file.
18-
This way you will be able to track your API's version info and keep your project up-to-date.
13+
For each new release you need implement the modifications from its pull requests in your project.
14+
It is recommended to copy the release info into your project's CHANGELOG.md file.
15+
This allows you to track your API's version and keep your project up-to-date with future releases.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ nav:
3131
- "Authorization": v5/core-features/authorization.md
3232
- "Content Validation": v5/core-features/content-validation.md
3333
- "Exceptions": v5/core-features/exceptions.md
34-
- "CORS": v5/core-features/cors.md
3534
- "Dependency Injection": v5/core-features/dependency-injection.md
3635
- "Error reporting": v5/core-features/error-reporting.md
3736
- Commands:
@@ -40,6 +39,7 @@ nav:
4039
- "Display available endpoints": v5/commands/display-available-endpoints.md
4140
- "Generate tokens": v5/commands/generate-tokens.md
4241
- Tutorials:
42+
- "Setting up CORS": v5/tutorials/cors.md
4343
- "Creating a book module": v5/tutorials/create-book-module.md
4444
- "Token authentication": v5/tutorials/token-authentication.md
4545
- "API Evolution": v5/tutorials/api-evolution.md

0 commit comments

Comments
 (0)