Skip to content

Commit acf8daf

Browse files
committed
Movie Rest example - Fixed a cross domain issue - DELETE and PUT should return HttpResult - else we get an error in the browser.
1 parent 6188264 commit acf8daf

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/ServiceStack.MovieRest/MovieService.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ServiceStack.MovieRest
1515
{
1616
[Description("GET or DELETE a single movie by Id. Use POST to create a new Movie and PUT to update it")]
17-
[RestService("/movies", "POST,PUT,PATCH")]
17+
[RestService("/movies", "POST,PUT,PATCH,DELETE")]
1818
[RestService("/movies/{Id}")]
1919
public class Movie
2020
{
@@ -88,7 +88,14 @@ public override object OnPost(Movie movie)
8888
public override object OnPut(Movie movie)
8989
{
9090
DbFactory.Exec(dbCmd => dbCmd.Update(movie));
91-
return null;
91+
92+
return new HttpResult()
93+
{
94+
StatusCode = HttpStatusCode.NoContent,
95+
Headers = {
96+
{ HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + movie.Id }
97+
}
98+
};
9299
}
93100

94101
/// <summary>
@@ -97,7 +104,14 @@ public override object OnPut(Movie movie)
97104
public override object OnDelete(Movie request)
98105
{
99106
DbFactory.Exec(dbCmd => dbCmd.DeleteById<Movie>(request.Id));
100-
return null;
107+
108+
return new HttpResult()
109+
{
110+
StatusCode = HttpStatusCode.NoContent,
111+
Headers = {
112+
{ HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + request.Id }
113+
}
114+
};
101115
}
102116
}
103117

0 commit comments

Comments
 (0)