Skip to content

Commit e09baf2

Browse files
committed
Merge pull request #9 from assaframan/master
Movie Rest example - Fixed PUT to update record. Added cross domain support.
2 parents 0146bdd + 6188264 commit e09baf2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/ServiceStack.MovieRest/Global.asax.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ public override void Configure(Container container)
2424
resetMovies.Post(null);
2525

2626
Routes
27-
.Add<Movie>("/movies", "POST,PUT")
27+
.Add<Movie>("/movies")
2828
.Add<Movie>("/movies/{Id}")
2929
.Add<Movies>("/movies")
3030
.Add<Movies>("/movies/genres/{Genre}");
31+
32+
SetConfig(new EndpointHostConfig
33+
{
34+
GlobalResponseHeaders = {
35+
{ "Access-Control-Allow-Origin", "*" },
36+
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
37+
{ "Access-Control-Allow-Headers", "Content-Type, X-Requested-With" },
38+
},
39+
//EnableFeatures = onlyEnableFeatures,
40+
//DebugMode = true, //Show StackTraces for easier debugging
41+
});
42+
3143
}
3244
}
3345

src/ServiceStack.MovieRest/MovieService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
using ServiceStack.OrmLite;
1010
using ServiceStack.ServiceInterface;
1111
using ServiceStack.Text;
12+
using ServiceStack.ServiceHost;
1213

1314
namespace ServiceStack.MovieRest
1415
{
1516
[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")]
18+
[RestService("/movies/{Id}")]
1619
public class Movie
1720
{
1821
public Movie()
@@ -84,7 +87,7 @@ public override object OnPost(Movie movie)
8487
/// </summary>
8588
public override object OnPut(Movie movie)
8689
{
87-
DbFactory.Exec(dbCmd => dbCmd.Save(movie));
90+
DbFactory.Exec(dbCmd => dbCmd.Update(movie));
8891
return null;
8992
}
9093

@@ -99,6 +102,8 @@ public override object OnDelete(Movie request)
99102
}
100103

101104
[Description("Find movies by genre, or all movies if no genre is provided")]
105+
[RestService("/movies", "GET, OPTIONS")]
106+
[RestService("/movies/genres/{Genre}")]
102107
public class Movies
103108
{
104109
public string Genre { get; set; }

0 commit comments

Comments
 (0)