Random tips for API testing, local development, etc.

This page is a work in-progress that gives some example tools and commands for working with JSONJSON JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML., httpHTTP HTTP is an acronym for Hyper Text Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands. requests, and TSV files in the terminal. These composable tools and recipes can be very useful when testing OpenverseOpenverse Openverse is a search engine for openly-licensed media, including photos, audio, and video. Openverse is also the name for the collection of related code repositories that make up the project. find Openverse at https://openverse.org..

Command-line Tools

  • httpie gives you an http command, basically a bit friendlier version of curl
  • xsv is a toolkit for working with csv files
  • jq is a lightweight and flexible command-line JSON processor

Top ↑

Recipes

These are some semi-random examples of commands you can use while testing the Openverse APIAPI An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. and catalog.

Top ↑

Get a list of result IDs

Configure the search however you like; this example gets the first page of audio IDs.

http get 'localhost:8000/v1/audio/?format=json' | jq -r '.results[].id'

Here’s an example of this in use, used to bulk report a series of image IDs.

 http get 'localhost:8000/v1/images/?format=json' | jq -r '.results[].id'| xargs -I{} http post localhost:8000/v1/images/{}/report/ reason=mature description=testing --ignore-stdin

Top ↑

Select and display a sample of columns from a Catalog TSV file

This example selects the 9th and 10th columns from one of our Catalog .tsv files, grabs a sample of ten results, and displays them as a table.

xsv select 9,10 wordpress_image_v001_20220519164607.tsv  | xsv sample 10 | xsv table

Last updated: