Skip to content

Commit

Permalink
Added recognition for HTTP-Methods: POST, PUT, DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLongo committed Jan 11, 2015
1 parent aaa9e99 commit cb4eeea
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
17 changes: 16 additions & 1 deletion conf/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
"routes": [
{
"method":"GET",
"route":"/hello",
"route":"/helloworld",
"implementation":"de.tlongo.roscoe.routes.HelloWorldRoute"
},
{
"method":"POST",
"route":"/helloworld",
"implementation":"de.tlongo.roscoe.routes.SamplePostRoute"
},
{
"method":"PUT",
"route":"/helloworld",
"implementation":"de.tlongo.roscoe.routes.SamplePutRoute"
},
{
"method":"DELETE",
"route":"/helloworld",
"implementation":"de.tlongo.roscoe.routes.SampleDeleteRoute"
}
]
}
6 changes: 6 additions & 0 deletions src/main/java/de/tlongo/roscoe/core/Roscoe.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ private void go() {
configManager.getRoutes().forEach(route -> {
if (route.getMethod().equals("GET")) {
get(route.getRouteUrl(), route);
} else if (route.getMethod().equals("POST")) {
post(route.getRouteUrl(), route);
} else if (route.getMethod().equals("PUT")) {
put(route.getRouteUrl(), route);
} if (route.getMethod().equals("DELETE")) {
delete(route.getRouteUrl(), route);
}
});
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/de/tlongo/roscoe/routes/SampleDeleteRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tlongo.roscoe.routes;

import de.tlongo.roscoe.core.RoscoeRoute;
import spark.Request;
import spark.Response;

/**
* Created by tomas on 11.01.15.
*/
public class SampleDeleteRoute extends RoscoeRoute {

@Override
public Object handle(Request request, Response response) {
return "This is a sample delete route.";
}
}
16 changes: 16 additions & 0 deletions src/main/java/de/tlongo/roscoe/routes/SamplePostRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tlongo.roscoe.routes;

import de.tlongo.roscoe.core.RoscoeRoute;
import spark.Request;
import spark.Response;

/**
* Created by tomas on 11.01.15.
*/
public class SamplePostRoute extends RoscoeRoute {

@Override
public Object handle(Request request, Response response) {
return "This is a sample post route.";
}
}
16 changes: 16 additions & 0 deletions src/main/java/de/tlongo/roscoe/routes/SamplePutRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tlongo.roscoe.routes;

import de.tlongo.roscoe.core.RoscoeRoute;
import spark.Request;
import spark.Response;

/**
* Created by tomas on 11.01.15.
*/
public class SamplePutRoute extends RoscoeRoute {

@Override
public Object handle(Request request, Response response) {
return "This is a sample put route.";
}
}

0 comments on commit cb4eeea

Please sign in to comment.