{"id":49542,"library":"trust-rest","title":"Trust REST","description":"Trust REST is a REST API testing library for Node.js (v2.1.0) that simplifies integration testing of RESTful services with a declarative API. Released under the MIT license, it provides a fluent interface for making HTTP requests and asserting responses, including support for JSON, headers, status codes, and body validation. Compared to alternatives like supertest, trust-rest focuses on lightweight syntax and minimal configuration. The library is stable with infrequent releases, primarily driven by bug fixes and minor feature additions. It supports both CommonJS and ES module systems, but users must ensure proper require/import usage to avoid runtime errors.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/frenchie4111/trust-rest","tags":["javascript"],"install":[{"cmd":"npm install trust-rest","lang":"bash","label":"npm"},{"cmd":"yarn add trust-rest","lang":"bash","label":"yarn"},{"cmd":"pnpm add trust-rest","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"used for making HTTP requests in tests","package":"superagent","optional":false}],"imports":[{"note":"Default export with CommonJS require works but import preferred.","wrong":"const trust = require('trust-rest')","symbol":"trust","correct":"import trust from 'trust-rest'"},{"note":"Named export for class types; available since v2.","wrong":"const { Trust } = require('trust-rest')","symbol":"Trust","correct":"import { Trust } from 'trust-rest'"},{"note":"CommonJS require yields the default export directly, not as part of an object.","wrong":"const { trust } = require('trust-rest')","symbol":"default","correct":"const trust = require('trust-rest')"}],"quickstart":{"code":"import trust from 'trust-rest';\n\nconst api = trust('https://jsonplaceholder.typicode.com');\n\n// Test GET endpoint\nconst getResponse = await api\n  .get('/posts/1')\n  .expect(200)\n  .expect('Content-Type', /json/)\n  .end();\n\nconsole.log('Response body:', getResponse.body);\n\n// Test POST endpoint\nconst postResponse = await api\n  .post('/posts')\n  .send({ title: 'foo', body: 'bar', userId: 1 })\n  .expect(201)\n  .expect(res => res.body.title === 'foo')\n  .end();\n\nconsole.log('Created post ID:', postResponse.body.id);","lang":"typescript","description":"Demonstrates basic GET and POST requests with status and header assertions using trust-rest."},"warnings":[{"fix":"Use default import: import trust from 'trust-rest'","message":"Using wrong import style: import { trust } instead of import trust","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Assign result to variable and avoid calling .end() again","message":"Calling .end() twice throws error","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to version 10 or later","message":"Support for Node.js <10 is dropped","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Always pass base URL: trust('http://example.com')","message":"API changed: trust() no longer accepts a base URL as optional parameter in v2","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'addit':82 'altern':54 'api':8,24 'assert':40 'avoid':99 'bodi':50 'bug':77 'code':48 'commonj':86 'compar':52 'configur':66 'declar':23 'driven':75 'ensur':94 'error':101 'es':88 'featur':81 'fix':78 'fluent':33 'focus':60 'header':46 'http':37 'includ':42 'infrequ':72 'integr':16 'interfac':34 'javascript':102 'json':45 'librari':10,68 'licens':29 'lightweight':62 'like':55 'make':36 'minim':65 'minor':80 'mit':28 'modul':89 'must':93 'node.js':12 'primarili':74 'proper':95 'provid':31 'releas':25,73 'request':38 'require/import':96 'respons':41 'rest':2,4,7,19,59 'runtim':100 'servic':20 'simplifi':15 'stabl':70 'status':47 'supertest':56 'support':43,84 'syntax':63 'system':90 'test':9,17 'trust':1,3,58 'trust-rest':57 'usag':97 'user':92 'v2.1.0':13 'valid':51","created_at":"2026-06-07T17:02:17.911147+00:00","updated_at":"2026-06-07T17:02:17.911147+00:00","problems":[{"fix":"Use correct import: import trust from 'trust-rest' or const trust = require('trust-rest')","cause":"Incorrect import or require style leading to undefined","error":"TypeError: trust is not a function"},{"fix":"Store response in variable and use that variable","cause":"Calling .end() twice on same request","error":"Error: Can't set headers after they are sent"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/frenchie4111/trust-rest","github":"https://github.com/frenchie4111/trust-rest","docs":null,"changelog":null,"pypi":null,"npm":"trust-rest","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}