• Stars
    star
    104
  • Rank 328,637 (Top 7 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED - this package is no longer supported

Deprecated

DISCLAIMER - Development of this package is currently on hiatus. We are currently not actively developing this package due to both resource constraints and uncertainty about how well supported it will be in the future. We are using this in our active projects, so we will continue to do bug fixes as we encounter them, but feature requests may go unanswered. PRs are still welcome.

REST2DDP Meteor Atmosphere Package

Convert REST APIs into DDP publications for your client side to reactively consume.

Add it to your project meteor add okgrow:rest2ddp.

Examples

  • Scraping websites with yahoo tools (code)
  • Passing parameters to get windchills (code)
  • Passing tokens in header to get gov data (code)

1. Collection (Client and/or Server)

REST2DDP requires a Meteor collection to interact with. Typically this is called on the client but can be on the server or both as well.

BaseballPlayers = new Mongo.Collection('baseballPlayers');

2. Config Objects (Server)

REST2DDP.configs is a global array of objects which hold configuration settings for each publication. Since this object could hold private keys it is recommended to only have these configs on the server-side.

Setting Type Required Description
name string true Name of the publication to subscribe to.
collection string true Specify which collection to send data.
restUrl string true The URL of the REST call. Dynamic parameters are held by a dollar sign blocks, ${varName}.
jsonPath string true Tell REST2DDP where to find the array in the API response. The path must always be an array and end with a wildcard (*). Check out the jsonpath docs.
pollInterval number false Sets the interval in seconds of pinging the API. Defaults to 10 seconds.
headerKeys array false An array of strings. Specifies which keys are allowed in the header of a call. Good idea to set since clients can modify the header.
headers object false Pass an object of default key values passed with every call. Client can override key values. Values must be a string.
// -----------------
// BASIC EXAMPLE
// -----------------
REST2DDP.configs.push({
  name: 'basic-baseball-player-stats',
  collectionName: 'baseballPlayers',
  restUrl:'http://dev.mlb.com/api/teamStats&team=cubs',
  jsonPath: '$.results.players.*'
});

// -----------------
// ADVANCE EXAMPLE
// -----------------
var apiToken = process.env.MLB_API_TOKEN;

REST2DDP.configs.push({
  name: 'adv-baseball-player-stats',
  collectionName: 'baseballPlayers',
  restUrl:'http://dev.mlb.com/api/teamStats&team=${teamName}',
  jsonPath: '$.results.players.*',
  pollInterval: 30,
  headerKeys: ['token', 'Content-Type'],
  headers: {
    token:apiToken,
    'Content-Type': 'application/json'
  }
});

3. Subscribing (Client or Server)

On the client you will subscribe to REST2DDP like you would any other publication and pass it parameters. The name of the publication you are subscribing to will always be 'REST2DDP'.

Argument Type Required Description
1 string true Name of the publication you are subscribing to will always be 'REST2DDP'.
2 string true Name of configuration to call.
3 object false Takes upto two optional keys which are objects, variables: {object} and headers: {object}.
Template.playersList.onCreated(function () {
  var self = this;
  
  // -----------------
  // BASIC EXAMPLE
  // -----------------
  self.autorun(function () {
    self.subscribe('REST2DDP', 'basic-baseball-player-stats');
  });
  
  // -----------------
  // ADVANCE EXAMPLE
  // -----------------
  self.autorun(function () {
    self.subscribe('REST2DDP', 'adv-baseball-player-stats', {
      variables: {
        teamName: 'cubs'
      },
      headers: {}
    });
  });
});

How to help/future features

  • Support XML
  • Support single document returns

Contributing

Issues and Pull Requests are always welcome. Please read our contribution guidelines.

More Repositories

1

analytics

UNMAINTAINED! - Complete Google Analytics, Mixpanel, KISSmetrics (and more) integration for Meteor
JavaScript
213
star
2

meteor-persistent-session

Modifies Meteor's Session to store variables in the browser's `localStorage`
JavaScript
187
star
3

meteor-image-upload

DEPRECATED - this package is no longer supported
JavaScript
40
star
4

router-autoscroll

[DEPRECATED] Smart management of scroll position across route changes for iron and flow router
JavaScript
39
star
5

graphql-markdown

UNMAINTAINED! - Write markdown/frontmatter, generate GraphQL TypesDefs & Resolvers, query via GraphQL, and serve as html.🔥
JavaScript
39
star
6

iron-router-autoscroll

Deprecated - see okgrow/router-autoscroll instead.
JavaScript
38
star
7

auto-analytics

UNMAINTAINED! - Complete Google Analytics, Mixpanel, KISSmetrics (and more) integration for JavaScript applications.
JavaScript
28
star
8

meteor-react-demo

Source for the demo here: https://youtu.be/xcej5OboUVM
CSS
26
star
9

meteor-promise

DEPRECATED: Use deanius:promise instead
JavaScript
26
star
10

accounts-ui-react

UNMAINTAINED! - The Meteor accounts-ui we know and love, wrapped in React.
JavaScript
26
star
11

meteor-dotenv

DEPRECATED: - Load environment variables from .env for Meteor projects
JavaScript
23
star
12

railstoronto.com

Rails Toronto
CSS
22
star
13

meteor-text-search-demo

A demo app showing how to do full text search in Meteor 1.2
JavaScript
22
star
14

react-apollo-helpers

Experiments to simplify the DX of react-apollo
JavaScript
18
star
15

guides

How we do things at OK GROW!
JavaScript
16
star
16

graphql-fundamentals

A training repo for learning basic concepts in GraphQL on the client and server
JavaScript
15
star
17

advanced-graphql

A training repo for learning advanced concepts in GraphQL on the client and server
JavaScript
13
star
18

code-club

JavaScript
8
star
19

leaderboard-es6

Meteor's Leaderboard example ported to ES6, with notes
CSS
8
star
20

meteor-migrations

A zero-downtime database migrations package for Meteor
JavaScript
6
star
21

meteor-test-doubles

Meteor core API test doubles using testdouble.js
JavaScript
6
star
22

meteortoronto.com

A simple guide to the Meteor JS community in Toronto
CSS
5
star
23

rest2ddp-app

Publish a live updating DDP API for any existing REST API with no coding required
JavaScript
3
star
24

analytics-test-basic

Test app for okgrow:analytics package issue debugging
JavaScript
2
star
25

meteor-promise-docs

Deprecated. Use Deanius's repo instead
HTML
2
star
26

meteor-package-linter

Deprecated. Use Deanius' package instead
JavaScript
2
star
27

accounts-ui-react-example

Example for accounts-ui-react package
JavaScript
1
star
28

persistent-session-demo

A demo app for the meteor-persistent-session package
JavaScript
1
star