Skip to content

Commit

Permalink
Update examples (#420)
Browse files Browse the repository at this point in the history
* Update CRM example

* Update users example
  • Loading branch information
alexdebrie authored and mthenw committed May 2, 2018
1 parent 8c2da7d commit b6a0dde
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
21 changes: 10 additions & 11 deletions examples/crm-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ Finally, there are a few other relevant configuration sections of `serverless.ym
```yml
custom:
eventgateway:
space: <your space>
apiKey: <your API key>
url: <your URL> # e.g. tenant-myapp.slsgateway.com
accessKey: <your Access Key>

plugins:
- "@serverless/serverless-event-gateway-plugin"
```

This `serverless-event-gateway-plugin` adds additional functionality to register functions and subscriptions with the Event Gateway. The `eventgateway` section of the `custom` block configures the plugin with your space and api key. You may choose any space you want, as long as it hasn't already been claimed, and it will be available at `https://<space>.slsgateway.com`.
This `serverless-event-gateway-plugin` adds additional functionality to register functions and subscriptions with the Event Gateway. The `eventgateway` section of the `custom` block configures the plugin with your application URL and access key. [Sign up for both here](https://dashboard.serverless.com).

Once you've entered your space and API key, install your dependencies and deploy:
Once you've entered your Application URL and Access Key, install your dependencies and deploy:

```bash
$ npm install
Expand All @@ -74,7 +74,7 @@ Note that we only get a message that an event was emitted. Custom events are pro
You can check your function logs to make sure everything is working properly:

```bash
$ sls logs -f addUserToCRM -t
$ sls logs -f addUserToCRM
START RequestId: 7b8800f5-2d34-11e8-8165-171c6f09ec0e Version: $LATEST
2018-03-21 18:20:07.365 (+00:00) 7b8800f5-2d34-11e8-8165-171c6f09ec0e Saving user to CRM:
{ company: 'Test Corp, Inc.',
Expand All @@ -94,19 +94,18 @@ In the example above, we saw how to set up a consumer of events as well as how t
In this example, let's complete the story by emitting `user.created` events from our Users service. The easiest way to emit an event is to use the [`event-gateway-sdk`](https://github.com/serverless/event-gateway-sdk) for Node.
To use the SDK, you'll create an Event Gateway client configured for your space, then emit an event with the event name and payload to send.
To use the SDK, you'll create an Event Gateway client configured for your application, then emit an event with the event name and payload to send.
The `emit.js` file shows how you could use the SDK in your application:
```javascript
// emit.js

const SDK = require('@serverless/event-gateway-sdk');
const SPACE = 'examplestest';
const URL = 'tenant-myapp.slsgateway.com'

const eventGateway = new SDK({
url: `https://${SPACE}.slsgateway.com`,
space: `${SPACE}`
url: URL
})

function createUser(user) {
Expand Down Expand Up @@ -135,13 +134,13 @@ createUser(user);
The `createUser` function is similar to one you would have in your application -- save the new user to your database, then emit a `user.created` event that other services can subscribe to.
You can run this file as a test if you like. You'll need to edit the `SPACE` variable to match the space you created in your `serverless.yml`. Then just execute the file and check your function logs:
You can run this file as a test if you like. You'll need to edit the `APP` variable to match the application you used in your `serverless.yml`. Then just execute the file and check your function logs:
```bash
$ node emit.js
Emitted user.created event!
$ sls logs -f addUserToCRM -t
$ sls logs -f addUserToCRM
START RequestId: 5a11a5d8-2d36-11e8-ac4f-eb85ef6fadda Version: $LATEST
2018-03-21 18:33:29.796 (+00:00) 5a11a5d8-2d36-11e8-ac4f-eb85ef6fadda Saving user to CRM:
{ company: 'Big Corp, Inc.',
Expand Down
5 changes: 2 additions & 3 deletions examples/crm-service/emit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const SDK = require('@serverless/event-gateway-sdk')
const SPACE = 'examplestest'
const URL = 'tenant-myapp.slsgateway.com'

const eventGateway = new SDK({
url: `https://${SPACE}.slsgateway.com`,
space: `${SPACE}`
url: URL
})

function createUser (user) {
Expand Down
2 changes: 1 addition & 1 deletion examples/crm-service/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"@serverless/serverless-event-gateway-plugin": ">=0.4.0"
"@serverless/serverless-event-gateway-plugin": ">=0.6.0"
}
}
4 changes: 2 additions & 2 deletions examples/crm-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ provider:

custom:
eventgateway:
space: <your space>
apiKey: <your API key>
url: <your URL> # e.g. tenant-myapp.slsgateway.com
accessKey: <your Access Key>

plugins:
- "@serverless/serverless-event-gateway-plugin"
Expand Down
14 changes: 7 additions & 7 deletions examples/users-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,26 @@ Finally, there are a few other relevant configuration sections of `serverless.ym
```yml
custom:
eventgateway:
space: <your space>
apiKey: <your API key>
url: <your URL> # e.g. tenant-myapp.slsgateway.com
accessKey: <your Access Key>

plugins:
- "@serverless/serverless-event-gateway-plugin"
```

This `serverless-event-gateway-plugin` adds additional functionality to register functions and subscriptions with the Event Gateway. The `eventgateway` section of the `custom` block configures the plugin with your space and api key. You may choose any space you want, as long as it hasn't already been claimed, and it will be available at `https://<space>.slsgateway.com`.
This `serverless-event-gateway-plugin` adds additional functionality to register functions and subscriptions with the Event Gateway. The `eventgateway` section of the `custom` block configures the plugin with your Application URL and Access Key. You may get this by [signing up here](https://dashboard.serverless.com).

Once you've entered your space and API key, install your dependencies and deploy:
Once you've entered your Application URL and Access Key, install your dependencies and deploy:

```bash
$ npm install
$ sls deploy
```

Now let's give it a try! Using `curl` or in your browser, navigate to the `getUser` endpoint at `https://<space>.slsgateway.com/users/15`:
Now let's give it a try! Using `curl` or in your browser, navigate to the `getUser` endpoint at `https://<applicationURL>/users/15`:

```bash
$ $ curl -X GET https://examplestest.slsgateway.com/users/15 | jq "."
$ curl -X GET https://tenant-myapp.slsgateway.com/users/15 | jq "."
{
"id": "10",
"name": "Ariel Dach",
Expand All @@ -125,4 +125,4 @@ $ $ curl -X GET https://examplestest.slsgateway.com/users/15 | jq "."

It worked! You can try your `POST` and `DELETE` endpoints as well.

You can reuse this same space across multiple services using different endpoint paths to allow for agility across your team.
You can reuse this same Application URL across multiple services using different endpoint paths to allow for agility across your team.
2 changes: 1 addition & 1 deletion examples/users-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"@serverless/serverless-event-gateway-plugin": ">=0.4.0"
"@serverless/serverless-event-gateway-plugin": ">=0.6.0"
},
"dependencies": {
"faker": "^4.1.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/users-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ provider:

custom:
eventgateway:
space: <your space>
apiKey: <your API key>
url: <your URL> # e.g. tenant-myapp.slsgateway.com
accessKey: <your Access Key>

plugins:
- "@serverless/serverless-event-gateway-plugin"
Expand Down

0 comments on commit b6a0dde

Please sign in to comment.