How to use the cote.Requester function in cote

To help you get started, we’ve selected a few cote examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dashersw / microservices-workshop / api-gateway / index.js View on Github external
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')

const app = express()

app.use(bodyParser.json())

const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })

const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })

const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })

app.get('/restaurants', async (req, res) => {
    const restaurants = await restaurantsRequester.send({ type: 'list' })
    res.send(restaurants);
})

app.post('/order', async (req, res) => {
    const order = await orderRequester.send({ type: 'create order', order: req.body })
    const delivery = await deliveryRequester.send({ type: 'create delivery', order })

    res.send({ order, delivery })
})

app.listen(3000, () => console.log('listening'))
github dashersw / cote-workshop / services / purchase-service.js View on Github external
var cote = require('cote'),
    models = require('../models');

var purchaseResponder = new cote.Responder({
    name: 'purchase responder',
    namespace: 'purchase',
    respondsTo: ['buy']
});

var purchasePublisher = new cote.Publisher({
    name: 'purchase publisher',
    namespace: 'purchase',
    broadcasts: ['update']
});

var paymentRequester = new cote.Requester({
    name: 'payment requester',
    key: 'payment'
});

purchaseResponder.on('*', console.log);

purchaseResponder.on('buy', function(req, cb) {
    var purchase = new models.Purchase({});

    models.Product.get(req.productId, function(err, product) {
        if (product.stock == 0) return cb(true);

        paymentRequester.send({ type: 'process', userId: req.userId, price: product.price }, function(err) {
            if (err) return cb(err);

            product.stock--;
github dashersw / dockercloud-microservices / api-server / index.js View on Github external
var express = require('express');
var cote = require('cote');
var app = express();

var timeRequester = new cote.Requester({
    name: 'Time Requester'
});

app.get('/', function(req, res) {
    res.send('Hello World!');
});

app.get('/time', function(req, res) {
    timeRequester.send({type: 'time'}, function(time) {
        res.send(time);
    });
});

app.listen(3000, function() {
    console.log('API server listening on port 3000!');
});
github dashersw / microservices-workshop / api-gateway / index.js View on Github external
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')

const app = express()

app.use(bodyParser.json())

const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })

const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })

const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })

app.get('/restaurants', async (req, res) => {
    const restaurants = await restaurantsRequester.send({ type: 'list' })
    res.send(restaurants);
})

app.post('/order', async (req, res) => {
    const order = await orderRequester.send({ type: 'create order', order: req.body })
    const delivery = await deliveryRequester.send({ type: 'create delivery', order })

    res.send({ order, delivery })
})

app.listen(3000, () => console.log('listening'))
github icebob / microservices-benchmark / suites / remote.js View on Github external
(function () {
	const cote = require('cote');

	cote_resp = new cote.Responder({ name: 'bench-remote' });
	cote_req = new cote.Requester({ name: 'bench-remote' });
	
	cote_resp.on('add', (req, cb) => {
		cb(req.a + req.b);
	});	

	bench.add("Cote", done => {
		cote_req.send({ type: 'add', a: 5, b: 3 }, res => done());
	});

})();
github dashersw / cote-workshop / admin / server.js View on Github external
purchaseRequester.send({type: 'list'}, function(err, purchases) {
        res.send(purchases);
    });
});

var productRequester = new cote.Requester({
    name: 'admin product requester',
    namespace: 'product'
});

var userRequester = new cote.Requester({
    name: 'admin user requester',
    namespace: 'user'
});

var purchaseRequester = new cote.Requester({
    name: 'admin purchase requester',
    namespace: 'purchase'
});

server.listen(5000);

new cote.Sockend(io, {
    name: 'admin sockend server'
});
github dashersw / microservices-workshop / api-gateway / index.js View on Github external
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')

const app = express()

app.use(bodyParser.json())

const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })

const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })

const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })

app.get('/restaurants', async (req, res) => {
    const restaurants = await restaurantsRequester.send({ type: 'list' })
    res.send(restaurants);
})

app.post('/order', async (req, res) => {
    const order = await orderRequester.send({ type: 'create order', order: req.body })
    const delivery = await deliveryRequester.send({ type: 'create delivery', order })

    res.send({ order, delivery })
})
github dashersw / cote-workshop / admin / server.js View on Github external
res.send(users);
    });
});

app.get('/purchase', function(req, res) {
    purchaseRequester.send({type: 'list'}, function(err, purchases) {
        res.send(purchases);
    });
});

var productRequester = new cote.Requester({
    name: 'admin product requester',
    namespace: 'product'
});

var userRequester = new cote.Requester({
    name: 'admin user requester',
    namespace: 'user'
});

var purchaseRequester = new cote.Requester({
    name: 'admin purchase requester',
    namespace: 'purchase'
});

server.listen(5000);

new cote.Sockend(io, {
    name: 'admin sockend server'
});
github dashersw / cote-workshop / admin / server.js View on Github external
});
});

app.get('/user', function(req, res) {
    userRequester.send({type: 'list'}, function(err, users) {
        res.send(users);
    });
});

app.get('/purchase', function(req, res) {
    purchaseRequester.send({type: 'list'}, function(err, purchases) {
        res.send(purchases);
    });
});

var productRequester = new cote.Requester({
    name: 'admin product requester',
    namespace: 'product'
});

var userRequester = new cote.Requester({
    name: 'admin user requester',
    namespace: 'user'
});

var purchaseRequester = new cote.Requester({
    name: 'admin purchase requester',
    namespace: 'purchase'
});

server.listen(5000);

cote

A Node.js library for building zero-configuration microservices.

MIT
Latest version published 1 month ago

Package Health Score

71 / 100
Full package analysis