Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

battlefield-stats-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

battlefield-stats-express

A simple battlefield stats express middleware

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

battlefield-stats-express

A simple battlefield stats middleware for nodejs express.

Usage

npm install battlefield-stats-express
const express = require('express');
const battlefieldStats = require('battlefield-stats-express');
const app = express();

// Get or use your key from https://battlefieldtracker.com/site-api`
const bfs = battlefieldStats(YOUR_API_TOKEN);

app.use('/api', bfs)
app.listen(3000);

Now you can see results when you navigate to http://localhost:3000/api/Stats/DetailedStats?platform=3&displayName=Ravic

API Docs

For documentation use http://docs.trnbattlefield.apiary.io/ then replace https://battlefieldtracker.com/bf1/api/ with http://localhost:3000/api

Advanced Usage

POSTing json data

This middleware also supports POST requests if you are using body-parser - which will populate req.body with json.

Example using bodyParser to parse json
const express = require('express');
const bodyParser = require('body-parser');
const battlefieldStats = require('battlefield-stats-express');

const app = express();
const bfs = battlefieldStats(YOUR_API_TOKEN); // obtained from https://battlefieldtracker.com/site-api

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/api', bfs)

app.listen(3000);

When the json is sent via POST it is then parsed where the query params mentioned in documentation reflect json key value pairs.

For example the following json is equivelant to displayName=Ravic&platform=3

{
  "displayName": "Ravic",
  "platform": 3
}

Applying more middlewares

If you wish, you can have this middleware just add the data from the battlefield tracker service to the request object, then do something else with your own handler.

const bfs = battlefieldStats(YOUR_API_TOKEN, false)
app.use('/api', bfs);
app.use('/api', function (req, res, next) {
  // lets just log it out before we send the data to the browser
  console.log(req.bfData);
  res.send(req.bfData);
});

Keywords

FAQs

Package last updated on 12 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc