11.1.0 • Published 16 days ago
aft-web-services v11.1.0
AFT-Web-Services
provides simplified HTTP REST request and response testing support
Installation
> npm i aft-web-services
Usage
the aft-web-services
package supports all standard HTTP methods like GET
, POST
, PUT
, DELETE
and UPDATE
by setting the HttpRequest.method
field
GET
// perform GET request and return a response
let response: HttpResponse = await httpService.performRequest({url: 'https://reqres.in/api/users?page=2'});
// deserialise a JSON or XML response into an object
let respObj: ListUsersResponse = httpData.as<ListUsersResponse>(response);
POST
// perform POST request and return a response
let response: HttpResponse = await httpService.performRequest({
url: 'https://reqres.in/api/users',
method: 'POST',
headers: {...HttpHeaders.ContentType.get(HttpHeaders.MimeType.applicationJson)},
postData: JSON.stringify({name: 'morpheus', job: 'leader'})
});
// deserialise a JSON or XML response into an object
let respObj: CreateUserResponse = httpData.as<CreateUserResponse>(response);
Advantages
- using this package can automatically log the request and response details using a
aft-core.ReportingManager
that can be passed in as part of theHttpRequest
to maintain the samelogName
within a single test - the
aft-web-services
classes rely on asynchronous promises meaning no worrying about callbacks - built-in support for redirects (HTTP Status Code 302) and http or https requests
- XML and JSON response data can be easily deserialised to objects using the
httpData.as<T>(response: HttpResponse)
function
NOTE:
XML to object deserialisation will use the following rules:
- element names become property names
- attributes become properties preceeded by an
@
symbol inside the element object - element text content is rendered in a special property named
keyValue
Ex:
<html>
<image src="./foo/bar/baz.jpg" />
<hr />
<span style="color:#808080" class="hidden rounded">
This is coloured
</span>
</html>
will become:
{
"html": {
"image": {
"@src": "./foo/bar/baz.jpg",
},
"hr": {},
"span": {
"@style": "color:#808080",
"@class": "hidden rounded",
"keyValue": "This is coloured"
}
}
}
11.1.0
16 days ago
11.0.0
22 days ago
10.3.0
1 month ago
10.2.2
2 months ago
10.2.0
10 months ago
10.2.1
10 months ago
10.0.0
12 months ago
10.1.0
12 months ago
8.1.0
2 years ago
8.0.0
2 years ago
8.3.0
2 years ago
8.2.0
2 years ago
8.4.1
2 years ago
8.4.0
2 years ago
8.4.2
2 years ago
7.0.0
2 years ago
9.0.0
2 years ago
6.0.1
2 years ago
4.0.1
3 years ago
5.0.1
3 years ago
4.0.0
3 years ago
5.0.0
3 years ago
2.0.0
3 years ago
1.0.1
4 years ago
1.0.0
4 years ago