# API - Username instead of id on \_by/\_mby

**URL:** <https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063>\
**Category:** Support\
**Created:** [September 4, 2021, 6:38pm UTC](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063 "2021-09-04T18:38:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ronaldaug](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ronaldaug/32/260_2.png) [@ronaldaug](https://discourse.getcockpit.com/u/ronaldaug)\
**Post date:** [September 6, 2021, 6:53am UTC](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063/6 "2021-09-06T06:53:49Z")

</div>

> [@linhous](#):
>
> is there anything in the documentation talking about creating this “bootstrap.php” file?

I don’t think the official docs have the detail about building `addons` and doing some logic on `hook events`.  
I can share you how I understand it.

> Disclaimer - the below information is based on my experience, so I could be wrong

`config/bootstrap.php` is like an init file. But it’s used for general purpose and you can add your common codes inside it.

For a specific type of init file, you can create your own addon under addons directory.  
So, it would be something like this - `addons/{your_addon_name}/bootstrap.php`

* * *

Let me explain how a very simple `addon` works.

```php
if (COCKPIT_API_REQUEST) {
    $app->on('cockpit.rest.init', function ($routes) use ($app) {
        $routes['test'] = function () use ($app) {
             $my_variable = $this->param('my_variable'); 
        }
     } 
}

```

### API Authentication

`COCKPIT_API_REQUEST` is API authentication / middleware

```php
if(COCKPIT_API_REQUEST){
    // The requests must includes token to access this 
}

```

* * *

### Event

`cockpit.reset.init` is like your codes will execute when Cockpit CMS init.  
This is very similar to `Jquery` or `JS` events.

```auto
 $app->on('cockpit.rest.init', function ($routes) use ($app) {
         // do your logic here
     } 

```

So, you might say how do I know those events?  
Here is the list of Cockpit events.

> <https://github.com/raffaelj/cockpit-scripts/blob/master/cli/get-triggers_list-of-events.md>

* * *

### Routes

To declare routes, you can write as below.

```php
if (COCKPIT_API_REQUEST) {
    $app->on('cockpit.rest.init', function ($routes) use ($app) {
        $routes['test'] = function () use ($app) {
             // access api route at "api/test" and do your logic here 
       }
    })
}

```

This is an example `test` route, so you can access your route like `/api/test`

* * *

### Request Parameters

You can simply grab the request parameter like `$this->param("my_variable")`

e.g

```php
     $my_variable = $this->param('my_variable'); 

```

* * *

### Lime framework

Cockpit was built on top of `Lime` micro php framework [https://github.com/agentejo/lime](https://github.com/agentejo/lime)  
So, most of it basic functions would be the same as lime.

You can also learn from this scripts list by @raffaelj

> **[GitHub - raffaelj/cockpit-scripts: A collection of code snippets with annotations to...](https://github.com/raffaelj/cockpit-scripts)**
>
> A collection of code snippets with annotations to modify Cockpit CMS

Hope this also help someone.

---

_[View the full topic](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063)._
