Installations
npm install protractor-api-resource
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.11.1
NPM Version
5.6.0
Score
37.5
Supply Chain
85.4
Quality
65.8
Maintenance
25
Vulnerability
93.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (68.3%)
JavaScript (31.7%)
Developer
sudharsan-selvaraj
Download Statistics
Total Downloads
69,841
Last Day
14
Last Week
48
Last Month
260
Last Year
10,915
GitHub Statistics
4 Stars
12 Commits
3 Forks
3 Watching
1 Branches
1 Contributors
Bundle Size
1.50 kB
Minified
675.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.3
Package Id
protractor-api-resource@1.0.3
Unpacked Size
14.53 kB
Size
4.54 kB
File Count
8
NPM Version
5.6.0
Node Version
8.11.1
Total Downloads
Cumulative downloads
Total Downloads
69,841
Last day
100%
14
Compared to previous day
Last week
-20%
48
Compared to previous week
Last month
-17.7%
260
Compared to previous month
Last year
-46.5%
10,915
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
protractor-api-resource
API testing is now made simple with protractor. protractor-api-resource is a REST Client framework created using request npm module to use in protractor tests for making API calls. Register all service endpoints as individual service methods and reuse the same inside the test. Inspired from angular-resource project.
Features
- Create reusable methods for all service end points once and use it throughout the tests.
- Supports all rest API methods(GET,POST,PUT,PATCH and DELETE).
- Supports authentication protected endpoints.
- Can be used in any node js projects.
Why is it useful?
If you are using Protractor for e2e testing and you need to get test data from API then this module will come handy with lot of predefined functionalities.
Usage
Install using npm
$ npm install protractor-api-resource
Example
Using javascript, first import the npm module in your tests.
1const apiResource = require("protractor-api-resource").ProtractorApiResource
Javascript 
1describe("Test response for all REST API methods", function () { 2 3 var apiClient, serviceEnpoints = { 4 getPosts: { 5 path: "/posts/:postId:" 6 }, 7 createPost: { 8 path: "/posts", 9 method: "POST" 10 }, 11 updatePost: { 12 path: "/posts/:postId:", 13 method: "PUT" 14 }, 15 patchPost: { 16 path: "/posts/:postId:", 17 method: "PATCH" 18 }, 19 }; 20 21 beforeAll(function () { 22 apiClient = new apiResource("https://jsonplaceholder.typicode.com/"); 23 apiClient.registerService(serviceEnpoints); 24 }); 25});
Thats it. Now you can directly access the service endpoints from your tests as below.
1it("Test GET method", function (done) { 2 var expectedResponse = { 3 "userId": 1, 4 "id": 1, 5 "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", 6 "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" 7 }; 8 9 apiClient.getPosts({postId: 1}).toJSON().then(function (actualResponse) { 10 expect(actualResponse).toEqual(expectedResponse); 11 done(); 12 }); 13}); 14
For POST,PUT and PATCH calls, you can also send payloads like,
1it("Test POST method", function (done) { 2 var payLoad = { 3 title: 'foo', 4 body: 'bar', 5 userId: 1 6 }; 7 8 var expectedResponse = { 9 id: 101, 10 title: 'foo', 11 body: 'bar', 12 userId: 1 13 }; 14 //First parameter is for query params and second parameter is for request payload. 15 apiClient.createPost({}, payLoad).toJSON().then(function (actualResponse) { 16 expect(actualResponse).toEqual(expectedResponse); 17 done(); 18 }); 19});
toJson()
method will parse the API respose and returns the respective JSON object and toSting()
willl return the plain string.
What if the service enpoints are protected with authentication?
It's very simple. Just mention the type of authentication at the time of creating a object.
Basic authentication.
1var apiClient = new apiResource("https://jsonplaceholder.typicode.com/").withBasicAuth(username,password);
Token based authentication.
1var apiClient = new apiResource("https://jsonplaceholder.typicode.com/").withTokenAuthentication(token);
You can also modify the authencation type any time inside the tests using apiClient .withTokenAuthentication(token)
Reference
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More