I'm trying to implement a RESTful web service. I'm using your framework for the routing, mapping, and unit testing.
So I have this Query type that I declare 4 fields in, id, owner, sqlSource, and markedForDeletion. I also have a group to define the REST resource.
@web.Group("/queries")
class QueriesCollection {
@web.DefaultRoute(methods: const [web.GET])
List<Query> getAllQueries() {
// Retrieve every query in the collection.
}
@web.DefaultRoute(methods: const [web.POST])
Future<shelf.Response> createNewQuery(@Decode() Query newQuery) async {
print(newQuery);
// Retrieve every query in the collection.
final String queriesFSRoot = "./queries";
File queryFile = new File("$queriesFSRoot/${newQuery.id}.wql");
if (!await queryFile.exists()) {
// Does not exist, we can create it if the user has permission.
// TODO XXX: Check if the user has permissions.
queryFile.writeAsString(encode(newQuery));
var response = new shelf.Response(HttpStatus.OK, headers: {
"Location": "/queries/${newQuery.id}"
});
return response;
} else {
// Query already exists, return 409 CONFLICT.
var response = new shelf.Response(HttpStatus.CONFLICT);
return response;
}
}
}
As you can see, I want the Route to automagically decode the Query in the body. I'm testing it using this unit test...
Hi @luizmineo,
I'm trying to implement a RESTful web service. I'm using your framework for the routing, mapping, and unit testing.
So I have this
Query
type that I declare 4 fields in,id
,owner
,sqlSource
, andmarkedForDeletion
. I also have a group to define the REST resource.As you can see, I want the Route to automagically decode the
Query
in the body. I'm testing it using this unit test...My problem is that
newQuery
is always null in the Route when I run it through with the mock framework.As far as I know I'm doing things right, but obviously I'm not and was hoping you could help me point out my error.
Thanks!