npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nordnet-next-api

v5.1.2

Published

Nordnet nExt API Javascript client

Downloads

48

Readme

Nordnet nExt API Javascript client

NPM version Build Status Dependency Status

Isomorphic JS client for Nordnet nExt API. Client can be used both on the client and server side. Client should be used for making HTTP requests towards nExt API. See nExt API documentation for a list of possible requests.

Installation

NPM

npm install --save nordnet-next-api

Usage

Library can be used on the client and server side.

import api from 'nordnet-next-api';

api
  .get('https://api.test.nordnet.se/next/2')
  .then(({ status, data }) => console.log(status, data));
var api = require('nordnet-next-api');
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  api.get('https://api.test.nordnet.se/next/2')
    .then(function(response) {
      res.send(response);
  })
});

Authentication is required to be able to use nExt API. Authorization header can be used to pass session token when communicating to the API. See nExt API documentation for more details on how to get test account and authenticate against nExt API.

This lib does not use babel-polyfill, so you might have to add it yourself, e.g. if you are building for IE11.

In you application:

import 'babel-polyfill'; // at your application entry point

Or in webpack.config.js

{
  entry: ['babel-polyfill', 'your_app_entry.js']
}

API

  • api.get(url, params = {}, headers = {})
  • api.post(url, params = {}, headers = {})
  • api.postJson(url, params = {}, headers = {})api.post with { 'Content-type': 'application/json;' } in headers
  • api.put(url, params = {}, headers = {})
  • api.putJson(url, params = {}, headers = {})api.put with { 'Content-type': 'application/json;' } in headers
  • api.del(url, params = {}, headers = {})

Each method returns a Promise, which resolves or rejects with Object { response, data, status } where

Promise is rejected when HTTP status code is greater or equal 400.

url

Required
Type: String Example:

  • /api/2/login
  • /api/2/accounts/{accno}
  • /api/2/instruments/{instrument_id}?positions={positions}

Note: interpolated url params are taken from params argument. If url contains a key, which doesn't exist in params, promise will be rejected with Error.

params

Required
Type: Object
Default: {}

Object params is used to

  • interpolate url params.
  • if headers contains "Content-type": "application/json" for constructing request payload.
  • otherwise for constructing request body.

headers

Required
Type: Object
Default: {}

See Fetch API Headers

Basic usage

import api from 'nordnet-next-api';

api
  .get('https://api.test.nordnet.se/next/2/accounts/{accno}', { accno: 123456789 })
  .then(({ status, data, response }) => console.log(status, data, response));

Returned response contains

  • status (HTTP response status)
  • data (either JSON or plain string depending on Content-type header)
  • response (Response interface of Fetch API)

Setting root URL before querying

import api from 'nordnet-next-api';

api.setConfig({ root: 'https://api.test.nordnet.se/next/2' });

api.get('/accounts/{accno}', { accno: 123456789 })
  .then(response => console.log(response));

The following config keys are supported:

  • root sets base root URL
  • ntag set initial nTag value
  • clientid set the client-id default header

Passing path parameters

import { get } from 'nordnet-next-api';

get('https://api.test.nordnet.se/next/2/accounts/{accno}', { accno: 123456789 })
  .then(({ status, data }) => console.log(status, data));

Passing query parameters

import { get } from 'nordnet-next-api';

get('https://api.test.nordnet.se/next/2/news?days={days}', { days: 0 })
  .then(({ status, data }) => console.log(status, data));

Passing POST parameters

import { post } from 'nordnet-next-api';

post('https://api.test.nordnet.se/next/2/user/{key}', { key: 'foo', value: { bar: 'bar' }})
  .then(({ status, data }) => console.log(status, data));

Passing additional headers

import { get } from 'nordnet-next-api';

get('https://api.test.nordnet.se/next/2/markets/{market_id}', { market_id: 11 }, { 'Accept-Language': 'sv' })
  .then(({ status, data }) => console.log(status, data));

See tests under src/__tests__ for more examples.

Passing custom HTTP agent

import http from 'http';
import { get } from 'nordnet-next-api';

const agent = new http.Agent();

get('https://api.test.nordnet.se/next/2/markets/{market_id}', { market_id: 11 }, { 'Accept-Language': 'sv' }, { agent })
  .then(({ status, data }) => console.log(status, data));

Setting up default HTTP agent

import http from 'http';
import api from 'nordnet-next-api';

const agent = new http.Agent();

api.setConfig({ agent });

get('https://api.test.nordnet.se/next/2/markets/{market_id}', { market_id: 11 }, { 'Accept-Language': 'sv' })
  .then(({ status, data }) => console.log(status, data));

Example projects

nordnet-next-api is distributed with a two simple example projects.

Before proceeding, install dependencies and build the project:

npm install
npm run build

Run the client side example:

cd examples/client
npm install
npm start

Run the server side example:

cd examples/server
npm install
npm start

License

This Open Source project released by Nordnet is licensed under the MIT license.