All Projects → zapier → node-resthooksdemo

zapier / node-resthooksdemo

Licence: other
A simple node.js RESTHooks demo built upon the Sails Web Framework

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-resthooksdemo

ui5-webcomponents-sample-angular
UI5 Web Components Sample TODO application built with Angular.
Stars: ✭ 34 (-50%)
Mutual labels:  sample-code
blockchain
No description or website provided.
Stars: ✭ 28 (-58.82%)
Mutual labels:  sample-code
hana-developer-cli-tool-example
Learn how to build a developer-centric SAP HANA command line tool, particularly designed to be used when performing SAP HANA development in non-SAP tooling (for example from VS Code).
Stars: ✭ 73 (+7.35%)
Mutual labels:  sample-code
abap-platform-jak
The JSON ABAP Konverter
Stars: ✭ 16 (-76.47%)
Mutual labels:  sample-code
btp-workflow-management-opensap
This repository contain the exercises for the openSAP course "Improve Business Processes with SAP Workflow Management."
Stars: ✭ 30 (-55.88%)
Mutual labels:  sample-code
Myapplications
My Tutorials
Stars: ✭ 50 (-26.47%)
Mutual labels:  sample-code
pragmaconf17
A collection of slide decks, videos and other material from the Pragma Conference 2017 talks
Stars: ✭ 39 (-42.65%)
Mutual labels:  sample-code
cloud-espm-cloud-native
Enterprise Sales and Procurement Model (ESPM) Cloud Native is a project that showcases how an application can be made resilient by implementing resilience design patterns. This application is developed using Spring Boot framework and can be deployed locally as well as on SAP BTP, Cloud Foundry environment.
Stars: ✭ 29 (-57.35%)
Mutual labels:  sample-code
dbus-sample
Sample C/C++ code for basic D-Bus use case
Stars: ✭ 76 (+11.76%)
Mutual labels:  sample-code
FIDO-Server
Open-source FIDO server, featuring the FIDO2 standard.
Stars: ✭ 17 (-75%)
Mutual labels:  sample-code
ui5-cap-event-app
Showcase of SAP Cloud Application Programming Model and OData V4 with draft mode in a freestyle SAPUI5 app and an SAP Fiori elements app.
Stars: ✭ 70 (+2.94%)
Mutual labels:  sample-code
cloud-workflow-samples
Workflow sample projects as reference content. Users can download and import the content of this project to their tenant to understand and learn how to consume workflow.
Stars: ✭ 52 (-23.53%)
Mutual labels:  sample-code
cloud-mdk-tutorial-samples
Sample from the SAP mobile development kit tutorials demonstrating various components and features of the MDK in the context of an enterprise mobile solution.
Stars: ✭ 16 (-76.47%)
Mutual labels:  sample-code
ui5-webcomponents-sample-vue
UI5 Web Components Sample TODO application built with Vue.
Stars: ✭ 52 (-23.53%)
Mutual labels:  sample-code
gruniozerca-gamebuino
A Gamebuino port of a homebrew NES game.
Stars: ✭ 11 (-83.82%)
Mutual labels:  sample-code
opendaylight-sample-apps
Sample applications for use with OpenDaylight (https://www.opendaylight.org/)
Stars: ✭ 56 (-17.65%)
Mutual labels:  sample-code
iot-edge-samples
Showcase of various extension scenarios for SAP IoT Edge, intelligent edge computing software that provides "microservices at the edge" for Internet of Things (IoT).
Stars: ✭ 16 (-76.47%)
Mutual labels:  sample-code
cloud-cap-multitenancy
SAP Cloud Application Programming Model (CAP) sample code project with multitenancy using service manager-created SAP HANA containers for tenant data isolation.
Stars: ✭ 33 (-51.47%)
Mutual labels:  sample-code
ui5-webcomponents-sample-react
UI5 Web Components Sample TODO application built with React.
Stars: ✭ 47 (-30.88%)
Mutual labels:  sample-code
nodejs-rust-sample-module
A sample node module built with Rust. Calculates the closest airport to a given latlon coordinate.
Stars: ✭ 18 (-73.53%)
Mutual labels:  sample-code

Node.js RESTHooks Demo

This is a simple proof of concept that demonstrates how to setup rest hook in a basic sails.js application. While the concept and examples are simple the same basic concept should be applicable with the complexities of your application domain.

The Layout

This project consists of two servers: the Contactly application that is the latest startup to attempt to corner the CRM market and a client application (client_app.js) that represents some application hosted somewhere else on the internets that someone wants to use to extend the Contactly application.

Contactly

Running It

Running it assumes that you have node.js 0.10 or above instaled.

npm install
npm start

Visit http://localhost:1337 in a browser to view the web interface. You can also visit the RESTful API urls at:

Now from another terminal let's start up the client application that pretends to be an app that is extending our application via REST Hooks.

node client_app.js

Now if you visit the subscription endpoint again you should see that three subscriptions have been created (for create, update and delete).

$ curl -L http://localhost:1337/subscription                                                                                                          [17:23:52]
[
  {
    "target": "http://localhost:3000/create",
    "event": "contact.create",
    "createdAt": "2013-08-25T00:23:51.900Z",
    "updatedAt": "2013-08-25T00:23:51.900Z",
    "id": 1
  },
  {
    "target": "http://localhost:3000/update",
    "event": "contact.update",
    "createdAt": "2013-08-25T00:23:51.904Z",
    "updatedAt": "2013-08-25T00:23:51.904Z",
    "id": 2
  },
  {
    "target": "http://localhost:3000/delete",
    "event": "contact.delete",
    "createdAt": "2013-08-25T00:23:51.906Z",
    "updatedAt": "2013-08-25T00:23:51.906Z",
    "id": 3
  }
]

The client_app.js hosts its own http server with those three routes and on start it makes three calls to Contractly to subscribe to the corresponding events.

Now go poke around in the application and add a couple contacts. You should see something like this in the client_app server's console:

create                                                                                                                                              [17:23:54]
{ firstName: 'Jeffery',
  lastName: 'Lebowski',
  phoneNumber: '111-222-3333',
  emailAddress: '[email protected]',
  createdAt: '2013-08-25T00:29:20.482Z',
  updatedAt: '2013-08-25T00:29:20.482Z',
  id: 1 }

Cleaning Up

Finally, the client application has a route that basically says "Okay, I'm done. Don't let me know of anymore contact updates!".

$ curl -L http://localhost:3000/remove-subscriptions                                                                                                  [17:31:30]

Of which the console for the client application will display:

deleting subscription 1
deleting subscription 2
deleting subscription 3

Now if you view the subscriptions in the service you'll see that no more subscriptions are active.

$ curl -L http://localhost:1337/subscription                                                                                                          [17:31:49]
[]

And of course, poking around in the application at http://localhost:1337 we'll notice there is no longer any chatter in the console for the client application.

How We Do It

Sails provides the capability to hook into create, update and delete commands so we simply write a decorator that can hook into these dynamically and publish to resthook subscriptions whenever those actions occur on a model.

What You Should Do In Production

Obviously we cut a lot of corners in this demo to be very brief and to the point. For a production quality application it is recommended that you try to implement the following pieces.

  • Use proper validation and application security techniques
  • Implement a form of authentication (whether OAuth2, basic auth or API keys) to secure services exposed via REST hooks.
  • Limit the scope of what objects external services can subscribe to that are within their domain.

Also, while simply pushing notifications out asynchronously as we do in these examples, for a site with a heavy volume of traffic you may want to consider pushing model updates into a queue to a separate application to send the notifications out to subscribers. AMQP, Redis or even the queue-less ZeroMQ are all valid options here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].