Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Example application
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Aug 17, 2017
1 parent d834245 commit e363612
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cloud/wfm-user/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## wfm-user example

### Running example

ts-node example/index.ts

To test example execute in your console

curl http://localhost:3000/api/users?filter=example
35 changes: 35 additions & 0 deletions cloud/wfm-user/example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getLogger } from '@raincatcher/logger';
import * as Bluebird from 'bluebird';
import * as express from 'express';
import * as path from 'path';
import { User, UserController, UsersRepository } from '../src/index';

const app = express();

/**
* Simplified example UsersRepository.
* Implementation can fetch users from databases, LDAP etc.
*/
class ExampleRepository implements UsersRepository {
public retrieveUsers(filter: string, limit: number): Bluebird<User[]> {
const exampleUser = { id: 1, name: 'Example User' };
return Bluebird.resolve([exampleUser]);
}
}

// Create repository
const repository = new ExampleRepository();
// Create api
const api = new UserController(repository);

// Mount api into path
app.use('/api/users', api.buildRouter());

app.use(function(err: any, req: express.Request, res: express.Response, next: any) {
getLogger().error(err);
res.status(500).send(err);
});

app.listen(3000, function() {
getLogger().info('Example auth app listening on port 3000');
});

0 comments on commit e363612

Please sign in to comment.