Skip to content
Browse files

Improve documentation

  • Loading branch information...
1 parent e5b8a70 commit f0c0e81254b48cde2c04a6645f57d7817234655e @jfarcand jfarcand committed Jun 10, 2011
View
2 restsimple-api/src/main/java/org/sonatype/restsimple/api/Action.java
@@ -49,6 +49,8 @@ public Pet action(ActionContext<Pet> actionContext) throws ActionException {
}
}
+ * You can use the {@link TypedAction} for an implementation of an {@link Action}
+ *
* The de-serialization of the Request's body is always performed before the {@link Action#action} and the result can
* always be retrieved using {@link org.sonatype.restsimple.api.ActionContext#get()} The returned value of the
* {@link Action#action} will be serialized based on the information represented by the associated {@link ServiceHandler}.
View
33 restsimple-api/src/main/java/org/sonatype/restsimple/api/TypedAction.java
@@ -15,6 +15,39 @@
* Simple {@link Action} that delegate the HTTP method operation to proper method implementation of GET, POST, PUT and
* DELETE. By default all method are throwing an exception with the status code set to 405 (NOT SUPPORTED). Override the
* proper method.
+ * {@code
+ * public class PetstoreAction extends TypedAction<Pet, Pet> {
+ *
+ @Override
+ public Pet get(ActionContext<Pet> actionContext) {
+ String pathValue = actionContext.pathParams().get("pet");
+ Map<String, Collection<String>> headers = actionContext.headers();
+
+ Pet pet = pets.get(pathValue);
+ return pet;
+ }
+
+ @Override
+ public Pet post(ActionContext<Pet> actionContext) {
+ Map<String, Collection<String>> headers = actionContext.headers();
+ Map<String, Collection<String>> queryStrings = actionContext.paramsString();
+ Map<String, Collection<String>> matrixParams = actionContext.matrixString();
+
+ String pathValue = actionContext.pathParams().get("pet");
+
+ Pet pet = actionContext.get();
+ pets.put(pathValue, pet);
+ return pet;
+ }
+
+ @Override
+ public Pet delete(ActionContext<Pet> actionContext) {
+ String pathValue = actionContext.pathParams().get("pet");
+
+ return pets.remove(pathValue);
+ }
+ * }
+ * }
*
* @param <T>
* @param <V>

0 comments on commit f0c0e81

Please sign in to comment.
Something went wrong with that request. Please try again.