{"id":13978,"date":"2016-07-20T12:15:41","date_gmt":"2016-07-20T09:15:41","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=13978"},"modified":"2016-07-19T13:12:57","modified_gmt":"2016-07-19T10:12:57","slug":"testing-http-apis-supertest","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/","title":{"rendered":"Testing HTTP APIs with SuperTest"},"content":{"rendered":"<p>You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that layer, your only writing tests for yourself, your teammates, or others consuming your code-level interfaces.<\/p>\n<p>But what about your web-level interface? Your HTTP API is the interface you give others who depend on your code without even being able to see it (like the good ol\u2019, pre-open source days\u2026 right?).<\/p>\n<p>That outbound API needs at least as much love and attention (if not more!) than the internal, code-level APIs you write for yourself and friends.<\/p>\n<h2>Surface Cleaning Your API<\/h2>\n<p>HTTP APIs are the web-level \u201csurface area\u201d of your application. External developers \u2014 including the browser-client team \u2014 depend on this surface to build their code on top of it. Making sure it\u2019s dependable and does what it promises is invaluable to giving others a solid foundation to build upon.<\/p>\n<p>Recently, I\u2019ve been working on testing the <a href=\"https:\/\/www.w3.org\/TR\/annotation-protocol\/\">Web Annotation Protocol<\/a> which was designed as part of the <a href=\"http:\/\/w3.org\/annotation\">Web Annotation Working Group<\/a> at the <a href=\"http:\/\/w3.org\/\">W3C<\/a>. Unlike the code you\u2019re writing now, this protocol started its life as a specification and, as it has grown and changed, has been implemented to make sure the spec can do what it says it can.<\/p>\n<p>To test the Web Annotation Protocol, I started by implementing it within the <a href=\"https:\/\/github.com\/w3c\/web-platform-tests\">Web Platform Tests<\/a> system frequently used to test browser-side JavaScript APIs specified by various W3C Working Groups. I sat down to write some Python, receive some HTTP requests, and return some JSON.<\/p>\n<p>However, things quickly got bothersome as testing the internal Python API was only part of the puzzle. I needed to be sure <code>curl<\/code> and the browsers would get the correct output from my API, <em>and<\/em> I needed the ability to test it from \u201cacross the Web\u201d where the various intermediaries (proxies, coffee shops, etc.) might interfere.<\/p>\n<p>So I ended up testing my test server via a thing called SuperTest.<\/p>\n<h2>Meet SuperTest<\/h2>\n<p><a href=\"https:\/\/github.com\/visionmedia\/supertest\">SuperTest<\/a> is built on the fabulous Node and browser HTTP client called <a href=\"http:\/\/visionmedia.github.io\/superagent\/\">SuperAgent<\/a>.<\/p>\n<p>Here\u2019s what SuperAgent code to send a POST request looks like (cribbing from their opening example):<\/p>\n<pre class=\"brush:php\">request\r\n   .post('\/api\/pet')\r\n   .send({ name: 'Manny', species: 'cat' })\r\n   .set('X-API-Key', 'foobar')\r\n   .set('Accept', 'application\/json')\r\n   .end(function(err, res){\r\n     if (err || !res.ok) {\r\n       alert('Oh no! error');\r\n     } else {\r\n       alert('yay got ' + JSON.stringify(res.body));\r\n     }\r\n   });<\/pre>\n<p>SuperTest extends that basic (and wonderfully obvious) API with a singular <code>.expect()<\/code> function. With that singular addition, you can expect all kinds of things!<\/p>\n<h2>But First, Mix In Some Chai(.js)<\/h2>\n<p>Tasty tests (for me, anyhow) start with some Mocha and some Chai!<\/p>\n<ul>\n<li><a href=\"https:\/\/mochajs.org\/\">Mocha<\/a> is a test framework for Node and the browsers.<\/li>\n<li><a href=\"http:\/\/chaijs.com\/\">Chai<\/a> is a Behavior and\/or Test Driven Development assertion library. Mix them together with SuperTest, and you have a test-driven HTTP API development process.<\/li>\n<\/ul>\n<p>Here\u2019s one of the tests (along with the basic setup) that I\u2019ve cribbed from my <a href=\"https:\/\/github.com\/BigBlueHat\/web-annotation-protocol-tester\">Web Annotation Protocol Tester<\/a> code:<\/p>\n<pre class=\"brush:php\">\/\/ pull in assert.isTrue() and the rest\r\nvar assert = require('chai').assert;\r\nvar request = require('supertest');\r\nvar uuid = require('node-uuid');\r\n\r\nvar host_url = 'http:\/\/localhost:8080'\r\nvar container_url = host_url + '\/annotations\/';\r\n\r\ndescribe('MUSTs', function() {\r\n  describe('4. Annotation Containers', function() {\r\n    it.skip('An Annotation Server MUST provide one or more Containers');\r\n    it('MUST end in a \"\/\" character', function(done) {\r\n      assert.isTrue(container_url[container_url.length-1] === '\/');\r\n      done();\r\n    });\r\n  });\r\n\r\n  describe('4.1 Container Retrieval', function() {\r\n    container = request(container_url);\r\n    it('MUST support GET, HEAD, and OPTIONs methods', function(done) {\r\n      container\r\n        .get('')\r\n        .expect('Allow', \/GET\/)\r\n        .expect('Allow', \/HEAD\/)\r\n        .expect('Allow', \/OPTIONS\/)\r\n        .expect(200, done);\r\n    });\r\n  });\r\n});<\/pre>\n<p>When run, this outputs a command line report that looks similar to this screenshot:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/screenshot.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-13997\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/screenshot.png\" alt=\"screenshot\" width=\"702\" height=\"290\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/screenshot.png 702w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/screenshot-300x124.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/p>\n<p>One thing I like about the mix of Mocha, Chai, and SuperTest is this \u201cspec\u201d report output. In this case, I\u2019ve mapped the various test suites directly to the sections of the <a href=\"https:\/\/www.w3.org\/TR\/annotation-protocol\/\">Web Annotation Protocol<\/a> and written SuperTest requests to generate HTTP client requests in order to test the server that claims to implement the protocol.<\/p>\n<p>The first of these example tests uses some simple Chai <code>assert.isTrue()<\/code> goodness to check the shape of a URL. The second uses SuperTest to check that the <code>Allow<\/code> header is set and that it includes <code>GET<\/code>, <code>HEAD<\/code>, and <code>OPTIONS<\/code> methods. This means the server is claiming it allows those methods on the requested resource. There are other tests which test each of those actual methods.<\/p>\n<p>I built the Web Annotation Protocol Tester to test my personal implementations of the Web Annotation Protocol. The code and runtime environment is deliberately separate from the the server and intentionally designed to test any implementation of the Web Annotation Protocol. I didn\u2019t want to put these tests near the server code for fear of \u201ccheating\u201d or mixing them with code-level tests.<\/p>\n<p>The different sort of separation of concerns works as a handy forcing agent to induce good habits on the protocol implementer. It\u2019s TDD for APIs.<\/p>\n<h2>Setting Expectations<\/h2>\n<p>You can quaff more Mocha and Chai by digging into their documentation. Today, we\u2019ll focus on SuperTest\u2019s superness!<\/p>\n<p>The <a href=\"https:\/\/github.com\/visionmedia\/supertest#api\">SuperTest API<\/a> adds the single <code>.expect()<\/code> method to the <a href=\"http:\/\/visionmedia.github.io\/superagent\/\">SuperAgent API<\/a>. This single method, though, has a wide range of uses, which we\u2019ll explore in the next few sections.<\/p>\n<blockquote><p>In all these cases, the <code>fn<\/code> function receives the current <code>err<\/code>. If no function is passed, an error will be thrown. However, if there is an <code>.end()<\/code> function, errors will be passed to that and can be re-thrown or passed to Chai\u2019s <code>done()<\/code> method.<\/p><\/blockquote>\n<h2>.expect(status[, fn])<\/h2>\n<p>Asserting the response status code is something you\u2019ll do quite often. Use the number of the HTTP Status Code for the value of <code>status<\/code>.<\/p>\n<p>Check out <a href=\"http:\/\/httpstat.us\/\">httpstat.us<\/a> or <a href=\"https:\/\/httpstatus.es\/\">httpstatus.es<\/a> or <a href=\"https:\/\/http.cat\/\">http.cat<\/a> if you need help deciding which status to check (or if you just need a great cat photo to display along with the error message).<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/416.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-13998\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/416.jpg\" alt=\"416\" width=\"750\" height=\"600\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/416.jpg 750w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/07\/416-300x240.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/p>\n<p>For instance:<\/p>\n<h2>.expect(status, body[, fn])<\/h2>\n<p>As in the previous section, <code>status<\/code> is a number, and <code>body<\/code> can be either a string (for an exact match scenario) or a regular expression (which is likely more useful).<\/p>\n<p>This one can be very handy for testing error code messages, such as:<\/p>\n<pre class=\"brush:php\">request(base_url).get(broken_url).expect(404, \/not found\/ig);<\/pre>\n<p>Or you may just want to be sure a certain key is returned in the JSON object if the response was successful:<\/p>\n<pre class=\"brush:php\">request(base_url).get(broken_url).expect(201, \/created\/ig);<\/pre>\n<p>You can also do an exact match on the parsed JSON object (assuming you\u2019re using JSON). See the next section for an example.<\/p>\n<h2>.expect(body[, fn])<\/h2>\n<p>In this case, you can focus your error message on the problems with the content of the response. For example:<\/p>\n<pre class=\"brush:php\">request(base_url).get('users').expect(\/total\/, function() {\r\n  throw new Error('Users list must have a `total` key);\r\n});<\/pre>\n<p>Often, though, you\u2019ll want to do more than a singe RegEx check on the response content. Hang in there, that option\u2019s around the corner!<\/p>\n<h2>.expect(field, value[, fn])<\/h2>\n<p>Asserting a header field and its value is one of the most common API tests. Here you can use a string equivalency test or a RegEx. Which one you pick will really just depend on the header you\u2019re checking. We saw the RegEx option in use with the <code>Allow<\/code> headers in the Web Annotation Protocol example. Here\u2019s a scenario where you might want an exact match:<\/p>\n<pre class=\"brush:php\">request(base_url).get('users').expect('Content-Type', 'application\/json', function() {\r\n  throw new Error('Default response MUST be in `application\/json`);\r\n});<\/pre>\n<h2>.expect(function(res) {})<\/h2>\n<p>This is the catch-all <code>.expect<\/code> option for checking the request according to anything not handled by the earlier examples. You get the whole <a href=\"http:\/\/visionmedia.github.io\/superagent\/#response-properties\">request object sent down from SuperAgent<\/a>. Which means, your test function will have access to the raw response text (<code>res.text<\/code>), the parsed response content (<code>res.body<\/code>), the headers (<code>res.header<\/code> as an array with headers lowercased), the media type (<code>res.type<\/code>), the character set (<code>res.charset<\/code>), and of course the status.<\/p>\n<p>This is the most obvious place to do multiple key existence checking in your JSON documents:<\/p>\n<pre class=\"brush:php\">request(base_url).get('users').expect(function(res) {\r\n  if (!('total' in res.body) &amp;&amp; !('first' in res.body)) {\r\n    throw new Error('Missing pagination information and hypermedia controls');\r\n  }\r\n});<\/pre>\n<h2>Here\u2019s How it <code>.end(fn)<\/code>s<\/h2>\n<p>Now that all those expectations are set in your tests, you can make some clean console output in conclusion. If you add an <code>.end()<\/code> method to your chain of <code>.expect()<\/code> calls, it will get whatever error is thrown handed down. In addition to the error, this method also gets the response for one last processing, logging, or whatever.<\/p>\n<p>Additionally, it serves as an obvious statement that your code will perform the request and expectations you\u2019ve set and then invoke <code>fn(err, res)<\/code>.<\/p>\n<pre class=\"brush:php\">request(base_url).get('users')\r\n  .expect('Content-Type', 'application\/json', function() {\r\n    throw new Error('Default response MUST be in `application\/json`);\r\n  })\r\n  .expect(200)\r\n  .expect(function(res) {\r\n    if (!('total' in res.body) &amp;&amp; !('first' in res.body)) {\r\n      throw new Error('Missing pagination information and hypermedia controls');\r\n    }\r\n  })\r\n  .expect(function(err, res) {\r\n    \/\/ in this case, just rethrow it via Chai\r\n    if (err) return done(err);\r\n    \/\/ or if successful, just be done\r\n    done();\r\n  });<\/pre>\n<h2>SuperTest Your API!<\/h2>\n<p>So, the next time you\u2019re building an API and you want to be sure it\u2019s <a href=\"https:\/\/www.webcodegeeks.com\/javascript\/json-ld-building-meaningful-data-apis\/\">meaningful<\/a> or doing that <a href=\"https:\/\/www.webcodegeeks.com\/web-development\/hypermedia-apis-apache-couchdb\/\">hypermedia<\/a> thing, grab a can of SuperTest. It\u2019s proven to find errors you didn\u2019t know your API had and in at least half the time it takes to run those tests over and over using <code>curl<\/code> or a browser and reading the output with your eyes.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/blog.codeship.com\/testing-http-apis-supertest\/\">Testing HTTP APIs with SuperTest<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a>\u00a0Benjamin Young at the <a href=\"http:\/\/blog.codeship.com\/\">Codeship Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that layer, your only writing tests for yourself, your teammates, or others consuming your code-level interfaces. But what about your web-level interface? Your HTTP API is the interface you give &hellip;<\/p>\n","protected":false},"author":147,"featured_media":927,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[383,121],"class_list":["post-13978","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-supertest","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Testing HTTP APIs with SuperTest - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testing HTTP APIs with SuperTest - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-20T09:15:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Benjamin Young\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Young\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\"},\"author\":{\"name\":\"Benjamin Young\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/caa7920cfde365335817761979a72407\"},\"headline\":\"Testing HTTP APIs with SuperTest\",\"datePublished\":\"2016-07-20T09:15:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\"},\"wordCount\":1309,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg\",\"keywords\":[\"SuperTest\",\"Testing\"],\"articleSection\":[\"Web Dev\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\",\"name\":\"Testing HTTP APIs with SuperTest - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg\",\"datePublished\":\"2016-07-20T09:15:41+00:00\",\"description\":\"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Dev\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/web-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Testing HTTP APIs with SuperTest\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/caa7920cfde365335817761979a72407\",\"name\":\"Benjamin Young\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/793ddd7d9809b369c04dbc92ea77a896112cc0a0e9a25417a43c17f4afb06f39?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/793ddd7d9809b369c04dbc92ea77a896112cc0a0e9a25417a43c17f4afb06f39?s=96&d=mm&r=g\",\"caption\":\"Benjamin Young\"},\"description\":\"Benjamin Young is a User Experience Engineer and Information Architect. He also organizes @RESTFest &amp; @OpenUpstate.\",\"url\":\"https:\/\/www.webcodegeeks.com\/author\/benjamin-young\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testing HTTP APIs with SuperTest - Web Code Geeks - 2026","description":"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/","og_locale":"en_US","og_type":"article","og_title":"Testing HTTP APIs with SuperTest - Web Code Geeks - 2026","og_description":"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that","og_url":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-07-20T09:15:41+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg","type":"image\/jpeg"}],"author":"Benjamin Young","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Benjamin Young","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/"},"author":{"name":"Benjamin Young","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/caa7920cfde365335817761979a72407"},"headline":"Testing HTTP APIs with SuperTest","datePublished":"2016-07-20T09:15:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/"},"wordCount":1309,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg","keywords":["SuperTest","Testing"],"articleSection":["Web Dev"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/","url":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/","name":"Testing HTTP APIs with SuperTest - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg","datePublished":"2016-07-20T09:15:41+00:00","description":"You know tests are Good For You\u00ae. You probably even write unit tests and measure the code coverage of your business logic. Congrats! However, at that","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/web-dev-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/web-development\/testing-http-apis-supertest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Dev","item":"https:\/\/www.webcodegeeks.com\/category\/web-development\/"},{"@type":"ListItem","position":3,"name":"Testing HTTP APIs with SuperTest"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/caa7920cfde365335817761979a72407","name":"Benjamin Young","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/793ddd7d9809b369c04dbc92ea77a896112cc0a0e9a25417a43c17f4afb06f39?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/793ddd7d9809b369c04dbc92ea77a896112cc0a0e9a25417a43c17f4afb06f39?s=96&d=mm&r=g","caption":"Benjamin Young"},"description":"Benjamin Young is a User Experience Engineer and Information Architect. He also organizes @RESTFest &amp; @OpenUpstate.","url":"https:\/\/www.webcodegeeks.com\/author\/benjamin-young\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/147"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=13978"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/13978\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/927"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=13978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=13978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=13978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}