12.1.1 • Published 1 year ago
aft-web-services v12.1.1
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" } } }
12.1.1
1 year ago
12.1.0
1 year ago
12.0.1
1 year ago
12.0.0
1 year ago
11.2.1
1 year ago
11.2.0
1 year ago
11.1.1
1 year ago
11.1.0
1 year ago
11.0.0
1 year ago
10.3.0
1 year ago
10.2.2
1 year ago
10.2.0
2 years ago
10.2.1
2 years ago
10.0.0
2 years ago
10.1.0
2 years ago
8.1.0
3 years ago
8.0.0
3 years ago
8.3.0
3 years ago
8.2.0
3 years ago
8.4.1
3 years ago
8.4.0
3 years ago
8.4.2
3 years ago
7.0.0
3 years ago
9.0.0
3 years ago
6.0.1
3 years ago
4.0.1
4 years ago
5.0.1
4 years ago
4.0.0
4 years ago
5.0.0
4 years ago
2.0.0
4 years ago
1.0.1
5 years ago
1.0.0
6 years ago