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 🙏

© 2025 – Pkg Stats / Ryan Hefner

protractor-http-client

v1.0.4

Published

HTTP client to be used in protractor tests

Readme

protractor-http-client

HTTP Client library to use in protractor tests

Build Status

What this library is about

Are you using protractor ? me too, and it's awesome! This library is a little utility that allows you to make any HTTP call (GET, PUT, POST, ...) , leveraging the powerful request library.

This library allows you to call HTTP services before, after or during interactions within the browser.

Why is it useful?

for example, for setting up test data via REST API before a test is run, or cleaning up after a test has finished running.

It won't be easy to do the same with plain 'http' or 'request' module, as you will have to wait for the HTTP call promise to complete, before using the protractor browser calls.

Instead, you have to just call e.g.

http.post("/database/users", {
    username: "marco", password: "bigsecret"
})
browser.get("/login") // this will wait for the previous call to finish
// initiate login with "marco" user

and the subsequent calls to protractor API will wait until the previous call finishes.

Requirements

  • Protractor 3+ (tested with 3.3.0 and 4.0.14)
  • Node 4.2+

Usage

If using Javascript specs

const HttpClient = require("protractor-http-client").HttpClient

If using Typescript specs

import {HttpClient} from "protractor-http-client"
const http = new HttpClient("https://example.com/")

// HTTP GET
const userGetResponse:ResponsePromise = http.get("/users/marco");
// HTTP POST with JSON, automatically sets Content-Type: application/json
http.post("/users", {
    username: "marco", password: "bigsecret"
}));
// HTTP POST, with form data and custom content type
http.post("/form", "param1=value1&param2=value2", {
    "Content-Type": "application/x-www-form-urlencoded"
}));
// make HTTP calls fail and throw an exception when response code is not 2xx
// default behavior is to continue on any HTTP status code
http.failOnError = true

You have get, post, put, delete methods available. get and delete methods do NOT accept request body. For more complex requests, use the request method shown below.

Passing complex request options

You can pass any options accepted by the request library, by passing an object to the request method

let options = { .... }
http.request(options)

Helper methods on response to check status and body

let response:ResponsePromise = http.get("/users/marco")
let jsonResponse:JsonPromise = response.jsonBody
let stringBody:Promise<string> = response.stringBody
let rawBody:Promise<Buffer> = response.body

let jsonPropertyValue:JsonPromise = response.jsonBody.get("propertyName")

expect(response.statusCode).toEqual(200)
expect(response.header("Content-Type")).toEqual("application/json")
expect(response.stringBody).toEqual('{"username":"marco","password":"bigsecret"}')
expect(response.jsonBody.get("username")).toEqual("marco")

Example spec with API setup

describe("the login page", () => {
    beforeEach(() => {
        // create a user
        const postResponse = http.post("/users", {
            username: "marco", password: "bigsecret"
        });
        expect(postResponse.statusCode).toEqual(200)
    })
    afterEach(() => {
        // delete user
        const deleteResponse = http.delete("/users/marco");
        expect(deleteResponse.statusCode).toEqual(200)
    })

    it("will allow login with new user", () => {
        // now you can use the browser to login with the new user
        browser.get("/login");
        element(by.id("username")).sendKeys("marco")
        element(by.id("password")).sendKeys("bigsecret")
        element(by.id("login-button")).click()
        // expectations here
    })
})