All Projects → radarlabs → Api Diff

radarlabs / Api Diff

Licence: apache-2.0
A command line tool for diffing json rest APIs

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Api Diff

Grafanajsondatasource
Grafana datasource to load JSON data over your arbitrary HTTP backend
Stars: ✭ 146 (-10.98%)
Mutual labels:  api, rest, json
Api Client Generator
Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
Stars: ✭ 92 (-43.9%)
Mutual labels:  api, rest, json
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-70.12%)
Mutual labels:  api, rest, json
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+24039.02%)
Mutual labels:  api, rest, json
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (-35.37%)
Mutual labels:  api, rest, json
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+483.54%)
Mutual labels:  api, rest, json
Json Api Dart
JSON:API client for Dart/Flutter
Stars: ✭ 53 (-67.68%)
Mutual labels:  api, rest, json
Zerocode
A community-developed, free, open source, microservices API automation and load testing framework built using JUnit core runners for Http REST, SOAP, Security, Database, Kafka and much more. Zerocode Open Source enables you to create, change, orchestrate and maintain your automated test cases declaratively with absolute ease.
Stars: ✭ 482 (+193.9%)
Mutual labels:  api, rest, json
Restinstance
Robot Framework library for RESTful JSON APIs
Stars: ✭ 157 (-4.27%)
Mutual labels:  api, rest, json
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-36.59%)
Mutual labels:  api, rest, json
Spyke
Interact with REST services in an ActiveRecord-like manner
Stars: ✭ 591 (+260.37%)
Mutual labels:  api, rest, json
Aping
angular module to get and display data by adding html-attributes
Stars: ✭ 135 (-17.68%)
Mutual labels:  api, rest, json
Jikan
Unofficial MyAnimeList PHP+REST API which provides functions other than the official API
Stars: ✭ 531 (+223.78%)
Mutual labels:  api, rest, json
Dito
Dito.js is a declarative and modern web framework with a focus on API driven development, based on Objection.js, Koa.js and Vue.js – Released in 2018 under the MIT license, with support by Lineto.com
Stars: ✭ 44 (-73.17%)
Mutual labels:  api, rest, json
Networking
⚡️ Elegantly connect to a REST JSON Api. URLSession + Combine + Decodable + Generics = <3
Stars: ✭ 499 (+204.27%)
Mutual labels:  api, rest, json
Flask Restx
Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
Stars: ✭ 1,050 (+540.24%)
Mutual labels:  api, rest, json
Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+32248.78%)
Mutual labels:  api, rest, json
Api
HeadHunter API: документация и библиотеки
Stars: ✭ 324 (+97.56%)
Mutual labels:  api, rest, json
Behat Api Extension
API extension for Behat, used to ease testing of JSON-based APIs
Stars: ✭ 92 (-43.9%)
Mutual labels:  api, rest, json
Json Serverless
Transform a JSON file into a serverless REST API in AWS cloud
Stars: ✭ 108 (-34.15%)
Mutual labels:  api, rest, json

api-diff

This is a tool for comparing one json http server to another. It supports a wide variety of input formats as well as the ability to save a baseline run to compare against future runs.

This tool is probably most useful in scenarios involving search/ranking problems, where there are alogrithm and data changes over time that require manual evaluation of the wins and losses.

It also includes a script for talking to json http services with saved configurations.

Output / Demo

text (console) output

start of text diff

html output

html diff

Note that this is an interactive evaluation form for figuring out which queries improved and which got worse. Each result is assigned an id based on the md5 hash of the query params + delta, and scores are saved to local storage. in your web browser. This means if you're doing a lot of compares, where many of the diffs are the same between runs, you won't need to re-rank them.

tl;dr

Try it out yourself!

This is a contrived example because our old and new servers are the same, but they return random data, so it is a good way to quickly see diffs.

From CSV input:

api-diff \                                 ✔ 
  --old.host http://names.drycodes.com/ \
  --new.host http://names.drycodes.com/ \
  --endpoint "/10" \
  --extra_params separator=" " nameOptions=starwarsCharacters \
  --input_csv docs/examples/input-names-drycodes.csv

From a file of http paths

api-diff \
  --old.host http://names.drycodes.com/ \
  --new.host http://names.drycodes.com/ \
  --input_queries docs/examples/input-names-drycodes.txt

Compare two servers

api-diff \
  `# defaults to http, port 80` \
  --new.host localhost:3100 \
  --old.host localhost:4100 \
  `# csv input, use headings as query parameter keys` \
  --input_csv ~/RadarCode/geocode-acceptance-tests/input/addresses.csv \
  `# remap csv column "query" to query param "text"` \
  --key_map query=text \
  `# run against /v1/search on our hosts` \
  --endpoint /v1/search \
  `# extra options to append to every query` \
  --extra_params size=1 sources=oa,osm \
  `# ignore all fields named these things in computing our diff` \
  --ignored_fields bbox geometry attribution timestamp \
  `# filter down responses to the first entry in the "addresses" array \
  --response_filter '$.addresses[0]' \
  `# output an interactive html diff. other options are text and json` \
  --output_mode html \
  --output_file diffs.html

Generate a baseline

 api-diff generate-baseline \
   `# the host to run against` \
   --old.host localhost:3100 \
   `# input csv file with headers corresponding to cgi params` \
   --input_csv ~/RadarCode/geocode-acceptance-tests/input/addresses.csv \
   `# remap the "query" header in our csv to the "text" cgi param` \
   --key_map query=text  \
   `# run queries against this endpoint` \
   --endpoint /v1/search \
   `# add extra query params to every query` \
   --extra_params size=1 sources=osm,oa \
   > addresses-baseline.json

Compare against a baseline

 api-diff \
  --new.host https://pelias-staging.apicom.com \
  --input_json_baseline addresses-baseline.json \
  --ignored_fields bbox geometry attribution timestamp \ 
  --output_mode html \ 
  > diffs.html

Use api tool with a config file

# use config.hjson which defines staging & local envs
API_DIFF_CONFIG=config.hjson api-tool \
  --prod \
  --endpoint /geocode/forward \
  near="40.74,-74" \
  query="30 jay st"

Use compare tool with a config file

# use config.hjson which defines staging & local envs
API_DIFF_CONFIG=config.hjson api-diff
  --old.staging \
  --new.local \
  --input_csv ~/geocode-acceptance-tests/input/addresses.csv

This also works with a url because I've defined in my config file how auth works and where to find the keys, and what kinds of keys different hosts need

API_DIFF_CONFIG=config.hjson api-tool \
  "http://api.radar.io/v1/geocode/forward?query=30 jay st"

Because I've defined a "prod" entry in config.hjson, and put keys into .env, this command will execute wth the necessary authentication.

Installation

npm install -g @radarlabs/api-diff

To run any of the examples in this doc from this source tree, simply run yarn --silent command instead of command, so yarn --silent api-diff instead of api-diff

Usage

This tool might seem like it has a zillion options, but I promise, it's not that bad!

At it's core, you need to specify two servers (old and new), and an input configuration. There are a bunch of ways to do that.

Configuration

All of the tools in this repo can load a configuration file that makes it easy to have saved defaults of servers to compare. A config file is specified via the environment variable API_DIFF_CONFIG, wth the idea that you can have multiple configs (for different services, like an api server and a geocode server) and use shell aliases to wrap the config.

The config file is specified in hjson which allows for comments and trailing commas.

An example config looks like this

{
  # this will be uppercased as the prefix to api key env variables
  name: "apicom",

  # "param" or "header"
  # param means the key will be sent as a cgi param with 
  #     the key authParam defined below 
  # header means the key will be sent in the http 
  #     Authorization header. If your server expects a header like "Bearer XXXXXXX",
  #     then set the api key to that entire string.
  authStyle: "header",

  # only required if using authStyle="param"
  # authParam: "api_key",

  # optional, if using authStyle="header"
  # authType: "Basic",

  # first keyType listed here will be the default if a
  # keyType is not specified in the commandline options to # compare
  keyTypes: ['test', 'live'],

  hosts: {
    prod: {
      host: 'https://prod.api.com',
      aliases: ['production'],
    }
    staging: {
      host: 'https://staging.api.com',
    },
    local: {
      host: 'http://localhost:8000',
      keyEnv: 'staging',
    },
    user: {
      takesArg: true,
      host: 'https://USER-staging.api.com'
      keyEnv: 'staging',
    },
  }
}

This defines a pretty common server setup. There is a production API at prod.api.com, that uses https (the default is http). It implicitly defines a "prod" key env in our config. There is a staging api at staging.api.com with a "staging" key env. Additionally, developers run local apis at localhost:8000, which use staging keys and should be communicated with over http (the default). Finally, each user has their own staging env at USER-staging.api.com which again uses staging keys.

Authorization

api-diff looks in the shell environment for api keys if needed. It loads ~/.api-keys.env into its env. For this config, that file would look like:

# keys are name + keyEnv + keyType + KEY
# all uppercase, joined with underscores
APICOM_PROD_TEST_KEY=XXXX
APICOM_PROD_LIVE_KEY=XXXX
APICOM_STAGING_TEST_KEY=XXXX
APICOM_STAGING_LIVE_KEY=XXXX

If your server requires authorization in request params, set authStyle="param" and authParam to the request parameter name the server expects. If your server uses the HTTP Authoization header, then set authStyle="header" and (optionally) authType to what auth type prefix the server expects, such as "Basic" or "Bearer" - this can be omitted if your server takes bare keys in the Authoization header.

Our config defines two types of keys - test and live. It also defines two key environments. One for "prod" and one for "staging," the host configs for "local" and "user" are both configured to look in the "staging" key env"

Specifying a server

For compare, two servers must be specified, with --new.X and --old.X options. For the api tool, the server is specifed in the same way but without the "new/old." prefix.

Servers can be specified in two ways:

  • by using host entries from our config file. So --old.prod, --old.staging, --old.user blackmad etc would all work based on our examples (similarly, --new.staging, --new.prod, etc)
  • a combination of --old.host (required), --old.key (only if auth is needed). And similarly, --new.host, and --new.key

These can be mixed!

Reading queries

  • --input_params - the input file has one query per line, of the form param1=A%20B&param2=Z. requires --endpoint argument. --method used, defaults to GET.
  • --input_queries - the input file has one path + params per line, like /endpoint?param1=A%20&p2=Z. --method used, defaults to GET.
  • --input_csv - for reading csvs. Combined with --endpoint and --method
    • Assumes that the first line of the file is column headings, unless --key_map is used with all numeric keys
    • Column headings are used as parameter names
    • --key_map remaps column headings. --key_map query=text remaps the csv heading "query" to the query param "text". --key_map 0=text 1=near will cause the parser to assume the csv does not have named column headings (because all the keys are numbers), and will use the first column as the query param "text", the second as the query param "near"

other options

  • --concurrency - how many queries to run at a time per host
  • --timeout - per query timeout, defaults to 30s
  • --unchanged - whether or not to output unchanged queries, defaults to false
  • --ignored_fields - fields to leave out when computing differences from server responses

output options

  • --color - text mode only. whether or not to colorize the output. Defaults to true if sending to stdout, false if redirecting output. Use this option to force colorized output. Suggest always using it.
  • --output_mode - json, html or text (console output)
  • --output_file - defaults to stdout, where to output to
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].