I'm using vibe.d for my rest API. I have two methods: addUser
and getUser
. I used @path("/api/v3/users/")
, so now the URL should look like this: http://127.0.0.1:8080/api/v3/users/user. The POST method works fine with this URL, but I can't get the GET method to work.
I use the same url (?someParams), but the server responds with 404. I've noticed, that when I use URL http://127.0.0.1:8080/api/v3/users/user/user, it says "Unexpected 'u' when converting from type string to type int", but if I put anything else than user after the /, it throws 404 again.
I'm sure I must've overlooked some dumb mistake :D
Interface:
@path("/api/v3/auth/")
interface IUserAPI
{
/** Adding a user */
User addUser(string email, string firstName, string lastName, string password, string locale);
/** Getting a user by id */
User getUser(int id);
}
Class:
/** User API */
class UserAPI : IUserAPI {
/** Testing user */
User user;
/** Adding a user */
@safe
User addUser(string email, string firstName, string lastName, string password, string locale) {
user = User(1, 0, email, firstName, lastName, password, locale, 0, false, "","", 0, "");
return user;
}
/** Getting a user by id */
@safe
User getUser(int id) {
logInfo(id.to!string);
return user;
}
}<br>
Registering rest interfaces:
router.registerRestInterface(new UserAPI, MethodStyle.camelCase);
router.registerRestInterface(new LogsListAPI, MethodStyle.camelCase);
After some digging, I found my answer. When you use id as a parameter, then it puts it directly in the URL. Like http://whatever.com/api/1(id)/user.