@olenbetong/appframe-client
Simple client class to log in to an AppframeWeb website and run requests with the session.
Last updated a month ago by bjornarvh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @olenbetong/appframe-client 
SYNC missed versions from official npm registry.

Appframe Web Client

A simple client to communicate with an AppframeWeb website in a node.js environment.

Gettin started

Installation

Install using NPM:

npm install --save-dev @olenbetong/appframe-client

Usage

Import the client class, and pass username, password and hostname in an options object to the constructor. Call the login method to authenticate.

When authentication is complete, use the get or post methods to run requests to the AppframeWeb website.

const AppframeClient = require("@olenbetong/appframe-client");
const client = new AppframeClient({
  username: "mylogin",
  password: "Password1",
  hostname: "example.com"
});

const status = await client.login();
if (status.success) {
  const myResponse = await client.get("/my/api");
  const myApiData = JSON.parse(myResponse);

  console.log(myApiData);
} else {
  console.error(status.error);
}

If you want to use the client to log in, but use the session outside the client, you can get the session cookies using the getSessionCookies method.

const AppframeClient = require("@olenbetong/appframe-client");
const client = new AppframeClient({
  username: "mylogin",
  password: "Password1",
  hostname: "example.com"
});

const status = await client.login();
if (status.success) {
  const cookies = client.getSessionCookies();

  console.log(cookies);
  /**
   * {
   *   AppframeWebAuth: {
   *     creation: [Date],
   *     hostOnly: [bool],
   *     httpOnly: [bool],
   *     path: [string],
   *     secure: [bool],
   *     value: [string],
   *   },
   *   AppframeWebSession: {
   *     creation: [Date],
   *     hostOnly: [bool],
   *     httpOnly: [bool],
   *     path: [string],
   *     secure: [bool],
   *     value: [string],
   *   }
   * }
   */
} else {
  console.error(status.error);
}

Changelog

2.1.4 - 2019-06-06

  • Improved error message if unkown error causes login failed.
  • Update dependencies

2.1.2 - 2019-01-16

  • Removed obsolete stuff from README
  • Updated dependencies

2.1.1 - 2018-12-18

Changed

  • Git repository moved to olenbetong organization

2.1.0 - 2018-12-18

Added

  • getSessionCookies - New method to get session cookies

2.0.0 - 2018-12-14

Breaking changes

  • Client requests now return the body of the response instead of the response. If the content type is JSON, the body will be parsed before it is returned as an object.

1.0.4 - 2018-12-14

Changed

  • If server returns error on login, display the error instead of a login failed string.

1.0.3 - 2018-11-26

Changed

  • Updated dependencies

1.0.2 - 2018-11-26

Fixed

  • Handle requests that are redirected to login page

1.0.1 - 2018-11-16

Changed

  • Moved repository to GitHub

1.0.0 - 2018-11-09

  • Migrated client to it's own NPM package from @olenbetong/appframe-proxy

Current Tags

  • 2.1.6                                ...           latest (a month ago)

14 Versions

  • 2.1.6                                ...           a month ago
  • 2.1.5                                ...           a month ago
  • 2.1.4                                ...           a year ago
  • 2.1.3                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 25
Dependencies (5)
Dev Dependencies (7)

Copyright 2014 - 2016 © taobao.org |