API client to test endpoints over HTTP. Uses superagent under the hood

Overview

@japa/client

API client to test endpoints over HTTP. Uses superagent under the hood

github-actions-image npm-image license-image typescript-image

The API client plugin of Japa makes it super simple to test your API endpoints over HTTP. You can use it to test any HTTP endpoint that returns JSON, XML, HTML, or even plain text.

It has out of the box support for:

  • Multiple content types including application/json, application/x-www-form-urlencoded and multipart.
  • Ability to upload files.
  • Read and write cookies with the option to register custom cookies serializer.
  • Lifecycle hooks. A great use-case of hooks is to persist and load session data during a request.
  • All other common abilities like sending headers, query-string, and following redirects.
  • Support for registering custom body serializers and parsers.

Complete API documentation

Installation

Install the package from the npm registry as follows:

npm i @japa/api-client

yarn add @japa/api-client

Usage

You can use the assertion package with the @japa/runner as follows.

import { apiClient } from '@japa/api-client'
import { configure } from '@japa/runner'

configure({
  plugins: [apiClient('http://localhost:3333')]
})

Once done, you will be able to access the client property from the test context.

test('test title', ({ client }) => {
  const response = await client.get('/')
})
You might also like...

Blobernize your pictures with this all-new tool! Still under development, but it works for now.

Blobernize your pictures with this all-new tool! Still under development, but it works for now.

Still under development, but in a usable state image-blobernizer A very simple image-blobernizer made for the webbrowser using p5.js Live demo Require

Mar 23, 2022

A smart city community centered application I am building for the Hackers In Residence under the Nkwashi program

A smart city community centered application I am building for the Hackers In Residence under the Nkwashi program. Implementing solutions and automation for potential future problems in the city.

Apr 25, 2022

Website for HKU NLP group (under construction)

Website for HKU NLP group (under construction)

hkunlp.github.io A new website for HKU NLP group (under construction). For now this page will host our blog posts (get more info at this week's group

Nov 1, 2022

Receive confessions and messages anonymously! (Under development)

About ⚠️ This project is under heavy development! ⚠️ umamin is an ad-free and open-source platform for sending and receiving anonymous confessions! Ea

Dec 11, 2022

Under the Sea is an official AWS workshop delivered by AWS SAs and AWS Partners to help customers and partners to learn about AIOps with serverless architectures on AWS.

Under the Sea - AIOps with Serverless Workshop Under the Sea is an exciting MMORPG developed by the famous entrepreneur behind Wild Rydes, the most po

Nov 16, 2022

This blog is still under development! I present a project scope for science articles, it can now be used in production! But there are some details that need to be put up front.

Science-Blog 🛑 Attention! This blog is still under development! I present a project scope for science articles, it can now be used in production! But

Sep 19, 2022

A minimal yet powerful HTTP client/API testing tool made for speed.

A minimal yet powerful HTTP client/API testing tool made for speed.

req req is a lightweight, minimal yet powerful HTTP client slash API testing tool designed for speed. Contents Features Installation Documentation Con

Aug 29, 2022

Jester is a test-generation tool to create integration test code.

Jester is a test-generation tool to create integration test code.

Code Generator for Integration Tests Introduction Welcome to Jester: An easy-to-use web application that helps you create and implement integration te

Dec 12, 2022

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

OCPP-RPC A client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols (e.g. OCPP1.6J and OCPP2.0.1J). Re

Dec 30, 2022
Comments
  • Array values cast to `string` when length of array is `1`

    Array values cast to `string` when length of array is `1`

    Description

    I noticed that when an array value is assigned to a field and the length of the array is 1, the value is cast to a string.

    For example:

    Within a test, userRoles is an array

          const userRoles = [globalAdminRole.id]
    
          const response = await client
            .post(route('global_users.store'))
            .loginAs(loginUser!)
            .field('full_name', userAttributes.fullName)
            .field('email', userAttributes.email)
            .field('role_ids', userRoles)
    

    but in the controller, it is received as:

    {
      full_name: 'Gardner Johnson',
      email: '[email protected]',
      role_ids: '1'
    }
    

    However, if the length of the array is more than 1, an array is received in the controller.

          const userRoles = [globalAdminRole.id, '2']
    
          const response = await client
            .post(route('global_users.store'))
            .loginAs(loginUser!)
            .field('full_name', userAttributes.fullName)
            .field('email', userAttributes.email)
            .field('role_ids', userRoles)
    
    {
      full_name: 'Gardner Johnson',
      email: '[email protected]',
      role_ids: [ '1', '2' ]
    }
    

    Package version

    "@adonisjs/core": "^5.8.3",
    "@japa/api-client": "^1.4.0",
    "@japa/assert": "^1.3.4",
    "@japa/preset-adonis": "^1.1.0",
    "@japa/run-failed-tests": "^1.0.7",
    "@japa/runner": "^2.0.9",
    

    Relevant Information

    I'm also not certain if this behaviour is caused by Adonisjs Bodyparser or the Japa's API client. But I want to believe that this kind of behaviour won't occur within the Bodyparser middleware.

    opened by ndianabasi 4
Releases(v1.4.2)
  • v1.4.2(Sep 8, 2022)

    • docs(README): fix link to plugin docs 700c4fb
    • chore: remove github health files in favor of central .github repo 6f324a9
    • chore: update dependencies 2dfe2ae

    Full Changelog: https://github.com/japa/api-client/compare/v1.4.1...v1.4.2

    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Sep 3, 2022)

    • chore: add @japa/runner as a peer dependency 7c9640f
    • chore: update dependencies a245f5e

    Full Changelog: https://github.com/japa/api-client/compare/v1.4.0...v1.4.1

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jun 6, 2022)

  • v1.3.1(May 20, 2022)

    • fix: prefix http protocol to url constructed from HOST and PORT env vars 9b20120

    https://github.com/japa/api-client/compare/v1.3.0...v1.3.1

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(May 19, 2022)

  • v1.2.0(Apr 10, 2022)

    • refactor: make hooks property public on request class fe047b7
    • feat: introduce "onRequest" hook aee2a36
    • chore: update dependencies e1606a9

    https://github.com/japa/api-client/compare/v1.1.6...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.6(Apr 7, 2022)

    • improvement: use HOST and PORT env variables when no base url is provided c5796b3
    • chore: update dependencies 82adb29

    https://github.com/japa/api-client/compare/v1.1.5...v1.1.6

    Source code(tar.gz)
    Source code(zip)
  • v1.1.5(Apr 2, 2022)

  • v1.1.4(Mar 26, 2022)

    • fix: run cleanup hook when the request fails with 500 status code 0c43c68
    • fix: parameters for the hooks cleanup functions e0b98a5
    • refactor: make response.assert public to allow extensions to use it c0c348a

    https://github.com/japa/api-client/compare/v1.1.3...v1.1.4

    Source code(tar.gz)
    Source code(zip)
  • v1.1.3(Mar 26, 2022)

    • feat: share request this with the response f1627a6
    • chore: update dependencies eb13fc7

    https://github.com/japa/api-client/compare/v1.1.2...v1.1.3

    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(Mar 24, 2022)

    • docs(README): update plugin registration example e199186
    • test: improve tests coverage 6be0de8
    • feat: add clearTeardownHooks and clearSetupHooks methods 66e04b1

    https://github.com/japa/api-client/compare/v1.1.1...v1.1.2

    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Mar 23, 2022)

  • v1.1.0(Mar 23, 2022)

    • refactor: rename "assertUsingApiSpec" method to "assertAgainstApiSpec" d83a645
    • fix: assert response against the api schema and not just the body 0a99851
    • refactor: Use APIClient constructor to register hooks and serializers d7c5cce
    • refactor: allow registering global hooks using ApiClient constructor c68dccb

    https://github.com/japa/api-client/compare/v1.0.2...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Mar 23, 2022)

  • v1.0.1(Mar 23, 2022)

    • fix: breaking types c6a2da4
    • chore: update dependencies 401e3dc
    • chore: update dependencies 9b24280
    • chore: update dependencies 079e842

    https://github.com/japa/api-client/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Mar 23, 2022)

    • feat: add response assertions 1576035
    • refactor: raise exception when server status code >500 6daf7ed

    https://github.com/japa/api-client/compare/v0.0.1...v1.0.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Mar 21, 2022)

    The package is not finalized and docs are also missing.

    • chore: add publishConfig to package.json file 25763b7
    • chore: update package.json file d400d50
    • chore(package): add missing dependencies f35f16a
    • docs: fix broken link in PR template 6197009
    • docs(README): update docs aa2247e

    https://github.com/japa/api-client/compare/57d904b2169acd046bdaa9a6e05bc5acbbb4ea16...v0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Japa.dev
An API first testing framework for Node.js
Japa.dev
Automatically generated documentation for the Valorant API endpoints the client uses internally.

Valorant API Docs To read documentation and get started, see Docs This is a project designed to automatically document Valorant endpoints based on a J

Techdoodle 223 Dec 25, 2022
Create Route53 HealthChecks to monitor TCP, HTTP, HTTPS endpoints, CloudWatch Alarms and other Route53 HealthChecks

AWS CDK Route53 HealthCheck Create Route53 HealthChecks to monitor TCP, HTTP, HTTPS endpoints, to monitor CloudWatch Alarms and to monitor other Route

Pepperize 7 Dec 15, 2022
An unofficial companion tool created for use alongside PhotoPrism to enable API endpoints and automation.

PhotoPrism Helper PhotoPrism Helper is an unofficial companion tool created for use alongside PhotoPrism. This project isn't associated with the Photo

Ryan Miller 9 Dec 25, 2022
An API library of useful mocked endpoints to help you get your designs feeling lifelike with real data.

About Welcome to Mocked-API, this is a live API that can be accessed by anyone who needs data to test out their website, app, components etc. Hacktobe

Aaron Rackley 48 Dec 29, 2022
Its an app that uses a weather API with access to over 200,000 cities current weather conditons.

Weather App Its an app that uses a weather API with access to over 200,000 cities current weather conditons. Screenshots Links Live Site URL: live sit

Yusuf Lawal 5 Aug 17, 2022
📡Usagi-http-interaction: A library for interacting with Http Interaction API

?? - A library for interacting with Http Interaction API (API for receiving interactions.)

Rabbit House Corp 3 Oct 24, 2022
On-demand runtime webpack compilations over HTTP.

webpack-http-server On-demand runtime webpack compilations over HTTP. Overview This package is, effectively, an Express server that exposes webpack co

Artem Zakharchenko 4 Oct 20, 2022
An interceptor to validate and decode Pub/Sub push messages for endpoints

NestJS GCP Pub/Sub Interceptor Provides an Interceptor for NestJS to automagically validate and unwrap HTTP push messages from Google Cloud Platform's

Hiphops 3 Dec 15, 2022
convert markdown to html in under 5kb

convert markdown to HTML in under 5kb take a look at the to PHP translated version: https://github.com/SimonWaldherr/micromarkdown.php about License:

Simon Waldherr 201 Dec 8, 2022
Here are the projects I completed under freeCodeCamp courses

freeCodeCamp Projects Here are the projects I completed under freeCodeCamp courses. For an overview of the course certifications, please visit my free

Quỳnh Vương 0 Mar 1, 2022