Permalink
Browse files

Movie Rest example - Fixed a cross domain issue - DELETE and PUT shou…

…ld return HttpResult - else we get an error in the browser.
  • Loading branch information...
1 parent 6188264 commit acf8dafd070b794c97ff6f72c3891372af10b3c2 @assaframan assaframan committed May 16, 2012
Showing with 17 additions and 3 deletions.
  1. +17 −3 src/ServiceStack.MovieRest/MovieService.cs
@@ -14,7 +14,7 @@
namespace ServiceStack.MovieRest
{
[Description("GET or DELETE a single movie by Id. Use POST to create a new Movie and PUT to update it")]
- [RestService("/movies", "POST,PUT,PATCH")]
+ [RestService("/movies", "POST,PUT,PATCH,DELETE")]
[RestService("/movies/{Id}")]
public class Movie
{
@@ -88,7 +88,14 @@ public override object OnPost(Movie movie)
public override object OnPut(Movie movie)
{
DbFactory.Exec(dbCmd => dbCmd.Update(movie));
- return null;
+
+ return new HttpResult()
+ {
+ StatusCode = HttpStatusCode.NoContent,
+ Headers = {
+ { HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + movie.Id }
+ }
+ };
}
/// <summary>
@@ -97,7 +104,14 @@ public override object OnPut(Movie movie)
public override object OnDelete(Movie request)
{
DbFactory.Exec(dbCmd => dbCmd.DeleteById<Movie>(request.Id));
- return null;
+
+ return new HttpResult()
+ {
+ StatusCode = HttpStatusCode.NoContent,
+ Headers = {
+ { HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + request.Id }
+ }
+ };
}
}

0 comments on commit acf8daf

Please sign in to comment.