Search code examples
jqueryajaxposthttp-postapiblueprint

Drakov http status code 404 from ajax post


I use a drakov mock server with an api blueprint md file. I want to send a POST request, but I always get status code 404.

I use a simple jQuery code:

var url = "http://localhost:3000/student/1/setfinalcommit";
var data = {first: "exampl"};
$.ajax({
    url: url,
    type: 'post',
    dataType: 'json',
    contentType: "application/json",
    success: function (data) {
        console.log(data)
    },
    data: data
});

Although it doesn't work with my JS code, it works from curl: curl -H "Content-Type: application/json" -X POST -d '{"first" : "exampl"}' http://localhost:3000/student/1/setfinalcommit

My .md file:

Message [/student/{userid}/setfinalcommit]

Post to the first example [POST]

  • Request (application/json) First POST example with body

    • Body

      {"first": "exampl"}
      
  • Response 200 (application/json;charset=UTF-8)

    • Body

      {
          "first": "exampl",
          "status": "ok"
      }
      

My question is: Did I mess up the blueprint, or the ajax request?

Thanks!


Solution

  • I messed up the backend. I had to start the drakov like this:

    drakov -f myfile.md --autoOptions