# Methods

## GET

**Simple GET**

```php
$router->get("/",function(){
  // do something
})
```

**Pass parameter through route**

```php
$router->get("/user/:id",function($id){
  echo $id;
})
```

## POST

Post data must be **JSON** format

The below example is when user post to `/api` route, it will return posted data.

```php
$router->post("/api",function($post_data){
   echo json_encode($post_data);
})
```

> Note: Post doesn't accept route parameter like "/api/:id"

## PUT

The **post data** send via **PUT** method must includes **\_id** as object property & value&#x20;

```php
$router->put("/posts",function($put_data){

     // example $put_data
     // {
     //  _id:'C3BF55677CA8225208BD9B6D77895126',
     //  title:'Testing title',
     //  description:'Testing description'
     // }

    $post = DB::table('posts')->save($put_data);
    echo json_encode($post);
})
```

## DELETE

The **post data** send via **DELETE** method must includes **id** as **route parameter** (e.g /posts/C3BF55677CA8225208BD9B6D77895126)

```php
$router->post("/posts/:id",function($id){
   DB::table("posts")->delete($id);
})
```
