Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving spelling / grammar #89

Merged
merged 1 commit into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions docs/Documentation/services.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
## Services

Service is central part of any API that concentrate all features(operations) realted to some application entity.
Service define list of actions (operations) that performed on associated entity.
For example, for RESTful service there could be described 4 default operations using HTTP verbs for each of CRUD operations.
Service is central part of any API that concentrates on all features (operations) realted to some application entity.
Service define list of actions (operations) that is performed on an associated entity.
Example: for RESTful service, there could be 4 default operations using HTTP verbs for each of CRUD operations.

Each Service could be an separate class located in src/Service folder, or request could be passed through default FallbackService that implements default behavior.
Fallback service defined by setting Api.ServiceFallback and by default this is \CakeDC\Api\Service\FallbackService.
Each Service could be a separate class located in the src/Service folder, or a request could be passed through the default FallbackService that implements default behavior.
Fallback service is defined by setting Api.ServiceFallback and by default this is \CakeDC\Api\Service\FallbackService.

## Define routes

### Define using `$_actionsClassMap`

Most trival way to define custom action namespace for CRUD action is using of $_actionsClassMap that defines map between action type and namespace.
The most trival way to define custom action namespace for CRUD action is using $_actionsClassMap, which defines the map between action type and namespace.

```
protected $_actionsClassMap = [
'index' => '\App\Service\Blogs\IndexAction',
];
```

Redefining this variable it is easy to disable default CRUD actions like DELETE.
Redefining this variable - it is easy to disable default CRUD actions like DELETE.

### Define routes with `mapAction`.

More complex routes defined with mapAction method. that accept action's alias, action class name, and router config. Most logical way to define routes is Service::intialize method.
More complex routes defined with mapAction method. This route accepts action's alias, action class name, and router config. The most logical way to define routes is the Service::intialize method.


Lets define /posts/:id/:flagtype route that accept POST request.
Lets define /posts/:id/:flagtype route that accepts POST request.

```
use App\Posts\FlagAction;
Expand All @@ -44,9 +44,9 @@ use App\Posts\FlagAction;
}
```

In some cases you want to define route variable type. What if we want accept only two type of flags: 'spam' and 'inappropriate'.
In some cases you will want to define the route variable type. Perhaps you want to accept only two types of flags: 'spam' and 'inappropriate'.

In this case we should define variable regex and pass it to router definition.
In this case, we should define variable regex and pass it to router definition.

```
public function routerDefaultOptions()
Expand All @@ -64,18 +64,18 @@ In this case we should define variable regex and pass it to router definition.

```

Defining router this way requests with other values in flag field would be completely rejected and action execution would not happen.
Defining router this way requests that other values in the flag field would be completely rejected and action execution would not happen.


## Accessing router variables values from action.

Access to variables defined in action router very simple.
Access to variables defined in action router is very simple.

First of all in actions that has :id param, most obsious way is get this value from `$_id` property.
For actions that have :id param, the easiest way is to get the value from `$_id` property.

In case we need read additional parameters from parsed router he should read then from parsed route data available from actions using `getRoute()` method.
If you need to read additional parameters from parsed router, then you should read them from the parsed route data that is available from actions using the `getRoute()` method.

So if we want read flag type in action we could do next:
So if we want to read the flag type in action, we can do this:

```
public function execute()
Expand Down