0

This is my Slim function :

// Add a new task
$app->post('/task/', function (Request $request, Response $response) {
    $data = $request->getParsedBody();
    $task = $data['task'];
    $state = 1;
    $now = date("Y-m-d");

    $this->database->insert("task", [
        "task" => "$task",
        "status" => "1",
        "created_at" => "$now"
    ]);

    $return = ['id' =>  $this->database->id()];
    return $response->withJson($return);
});

I can't figure out how to set the POST data in Advanced REST Client ! If I put "task" parametre in "Headers" section, Slim can't get any data and inserts empty string for "task" column : enter image description here

Thanks :)

Sami
  • 717
  • 6
  • 28

1 Answers1

2

You need to tell Slim what kind of information you are including in the body by setting a Content-Type header:

In the header section add a header name/value pair:

Header Name -> Content-Type
Header Value -> application/json

Now in the body section add the json information you want parsed:

{"task" : "A new task"}

Slim will read the header and parse the body accordingly as Array type.

Scriptonomy
  • 3,975
  • 1
  • 15
  • 23