Permalink
Browse files

Added TDStartServer function

Provides a simple way to start TouchDB and get its root URL, so clients don't have to mess with the TDServer and TDURLProtocol classes.
Ideally this should be the only public API exported from TouchDB.
  • Loading branch information...
1 parent 2f2d20b commit 1253d8187a95a9eaab3901420ab88ea16e412368 @snej snej committed Jul 26, 2012
Showing with 18 additions and 0 deletions.
  1. +7 −0 Source/TDServer.h
  2. +11 −0 Source/TDServer.m
View
@@ -32,3 +32,10 @@
- (void) close;
@end
+
+
+/** Starts a TDServer and registers it with TDURLProtocol so you can call it using the CouchDB-compatible REST API.
+ @param serverDirectory The top-level directory where you want the server to store databases. Will be created if it does not already exist.
+ @param outError An error will be stored here if the function returns nil.
+ @return The root URL of the REST API, or nil if the server failed to start. */
+NSURL* TDStartServer(NSString* serverDirectory, NSError** outError);
View
@@ -143,6 +143,17 @@ - (void) tellDatabaseManager: (void (^)(TDDatabaseManager*))block {
+NSURL* TDStartServer(NSString* serverDirectory, NSError** outError) {
+ CAssert(![TDURLProtocol server], @"A TDServer is already running");
+ TDServer* tdServer = [[[TDServer alloc] initWithDirectory: serverDirectory
+ error: outError] autorelease];
+ if (!tdServer)
+ return nil;
+ return [TDURLProtocol registerServer: tdServer forHostname: nil];
+}
+
+
+
TestCase(TDServer) {
RequireTestCase(TDDatabaseManager);

0 comments on commit 1253d81

Please sign in to comment.