Created
November 19, 2015 19:11
-
-
Save RdeWilde/80b651771a8ce6410d4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: myapp | |
dependencies: | |
redstone: any | |
redstone_mapper: any | |
redstone_mapper_mongo: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library myapp; | |
import 'package:redstone/redstone.dart' as app; | |
import 'dart:async'; | |
import 'package:redstone_mapper_mongo/service.dart'; | |
import 'package:redstone/redstone.dart' as app; | |
import 'package:mongo_dart/mongo_dart.dart'; | |
import 'package:redstone_mapper/plugin.dart'; | |
import 'package:redstone_mapper_mongo/manager.dart'; | |
import 'package:redstone_mapper/mapper.dart'; | |
import 'package:redstone_mapper_mongo/metadata.dart'; | |
import 'package:shelf/shelf.dart' as shelf; | |
// Models | |
part 'models/user.dart'; | |
// API endpoints | |
part 'api/users.dart'; | |
main() { | |
var dbManager = new MongoDbManager("mongodb://localhost/myapp", poolSize: 3); | |
app.addPlugin(getMapperPlugin(dbManager)); | |
app.setupConsoleLog(); | |
app.start(); | |
} | |
MongoDb get mongoDb => app.request.attributes.dbConn; | |
const VERSION = "v1"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST --data '{"email":"my@email.tld"}' | |
-H "Content-Type: application/json" http://localhost:8080/api/v1/users/add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
part of myapp; | |
class User { | |
@Field() | |
String email; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
part of myapp; | |
@app.Group("/api/${VERSION}/users") | |
class Users extends MongoDbService<User> { | |
Users() : super("users"); | |
@app.Route("/list") | |
Future<List<User>> list() => find(); | |
@app.Route("/:id") | |
@Encode() | |
Future<User> one(String id) => findOne(where.id(ObjectId.parse(id))); // TODO? Refactor into extended MongoDbService | |
@app.Route("/add", methods: const[app.POST]) // Error !! | |
String add(@Decode() User user) => insert(user); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment