On Sun, 01 Jan 2017 21:28:30 GMT, Inquie wrote:

I am trying to create a simple rest server that responds to scripts that I attach to pages I visit(using Greasemonkey).

I cannot get the vibe.d project to respond to requests.

I have used the example project

import std.typecons : Nullable;
import vibe.d;
import std.stdio;

@path("/")
interface IMyAPI
{
	// GET /api/greeting
	@property string greeting();

	// PUT /api/greeting
	@property void greeting(string text);

	// POST /api/users
	@path("/users")
	void addNewUser(string name);

	// GET /api/users
	@property string[] users();

	// GET /api/:id/name
	string getName(int id);

	// GET /some_custom_json
	Json getSomeCustomJson();
}

I run this then try to make a request either using js or soapUI but they always fail with connection error.

The javascript request is

$.ajax({
  url: 'http://127.0.0.1/',
  type: 'GET',
  //contentType: "application/json; charset=utf-8",
  contentType: "application/json"
  dataType: "json",      
  data: 'greeting', // or $('#myform').serializeArray()
  success: function() { alert('GET completed'); },
  error: function (qXHR, exception) {   alert(JSON.stringify(qXHR)); },
  done: function(msg) { alert("DONE: " + msg ); }   

});

I am new to using rest so I do not know if I am doing something wrong, if it is a configuration issue, or what.

As far as I can see you don't have a route matching the root. If you want to make a request for the greeting method that needs to be in the URL, i.e. url: 'http://127.0.0.1/greeting'.

/Jacob Carlborg