Generators for radws applications
First, install Yeoman and generator-radws using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-radws
Then generate your new application:
yo radws
You will be prompted for a profile and a code bucket. The profile is used when executing aws cli commands, and the code bucket is the s3 bucket that is used to upload your application code.
This creates a DynamoDB table. To generate the table, all you need is the resource name:
yo radws:table ProductCatalog
By default, a table is created with Hash key 'Id' of type String. Or, you can pass in specific hash and range key information:
yo radws:table Forum --hash Name:String
yo radws:table Thread --hash ForumName:String --range Subject:String
yo radws:table Reply --hash Id:String --range ReplyDateTime:String
To generate a handler, pass a resource name and a handler name.
yo radws:handler "Hello World" greet
To generate a handler with access to a DynamoDB table, pass --table-access
, which sets up additional policies, and exposes the table name for the resource as an environment variable to the handler.
yo radws:handler ProductCatalog list --table-access
To generate a route, pass the resource name, the HTTP method name, and the handler to execute:
yo radws:route Forum GET list
This will create a route with the following mapping:
GET /forum => app/forum/handlers/forum_list.handler
You can use the --member
flag to build a route for a single record:
yo radws:route Forum DELETE destroy --member
This will map the following route:
DELETE /forum/{key} => app/forum/handlers/forum_destroy.handler
In this example, sending a DELETE request to a specific forum will execute a handler that deletes that forum. You can also specify the key name:
yo radws:route Forum DELETE destroy --member Name
Which creates the same mapping, but using the following route:
DELETE /forum/{name}
To use nested routes, use the --through
option:
yo radws:route Thread GET list --through Forum.Name
yo radws:route Reply GET list --through Forum.Name.Thread.Subject
This would create the following routes:
GET /forum/{name}/thread
GET /forum/{name}/thread/{subject}/reply
The CRUD generator creates a REST API for a resource with all CRUD operations. With a single command:
yo jeffws:crud Forum --hash Name:String
Is equivalent to typing the following commands:
yo jeffws:table Forum --hash Name:String
yo jeffws:handler Forum create --table-access
yo jeffws:handler Forum list --table-access
yo jeffws:handler Forum show --table-access
yo jeffws:handler Forum update --table-access
yo jeffws:handler Forum destroy --table-access
yo jeffws:route Forum POST create
yo jeffws:route Forum GET list
yo jeffws:route Forum GET show --member
yo jeffws:route Forum PUT update --member
yo jeffws:route Forum PATCH update --member
yo jeffws:route Forum DELETE destroy --member
MIT © Jeff Cooper