# aft-web-services

> Automated Functional Testing (AFT) module for testing web services over HTTP and HTTPS

Latest version **12.1.1** (published 2024-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install aft-web-services
pnpm add aft-web-services
yarn add aft-web-services
bun add aft-web-services
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 12.1.1 |
| Published | 2024-05-23 |
| First published | 2019-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 146.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jason Holt Smith |
| Maintainers | bicarbon8 |
| Keywords | aft, automation, e2e, integration, functional, web-services, rest |

## Links

- npm: https://www.npmjs.com/package/aft-web-services
- Repository: https://github.com/bicarbon8/automated-functional-testing
- Homepage: https://github.com/bicarbon8/automated-functional-testing#readme
- Issues: https://github.com/bicarbon8/automated-functional-testing/issues
- npm.io page: https://npm.io/package/aft-web-services

## Dependencies (3)

- [xmldoc](https://npm.io/package/xmldoc.md) ^1.3.0
- [aft-core](https://npm.io/package/aft-core.md) ^12.1.1
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Alternatives

- [@snazzah/davey](https://npm.io/package/@snazzah/davey.md) — 1.5M weekly downloads
- [@vendure/testing](https://npm.io/package/@vendure/testing.md) — 8.3K weekly downloads
- [vue-simple-context-menu](https://npm.io/package/vue-simple-context-menu.md) — 6.6K weekly downloads
- [cypress-webpack-preprocessor-v5](https://npm.io/package/cypress-webpack-preprocessor-v5.md) — 2.1K weekly downloads
- [@backstage/plugin-catalog-backend-module-puppetdb](https://npm.io/package/@backstage/plugin-catalog-backend-module-puppetdb.md) — 1.3K weekly downloads

## Recent versions

- 12.1.1 (latest) — 2024-05-23
- 12.1.0 — 2024-05-17
- 12.0.1 — 2024-05-16
- 12.0.0 — 2024-05-15
- 11.2.1 — 2024-05-10
- 11.2.0 — 2024-05-09
- 11.1.1 — 2024-05-07
- 11.1.0 — 2024-04-18
- 11.0.0 — 2024-04-12
- 10.3.0 — 2024-03-28
- 10.2.2 — 2024-03-07
- 10.2.1 — 2023-07-11
- 10.2.0 — 2023-07-07
- 10.1.0 — 2023-05-24
- 10.0.0 — 2023-05-18
- … 17 more at https://npm.io/package/aft-web-services/versions

## README

# 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
```typescript
// 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
```typescript
// 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 the `HttpRequest` to maintain the same `logName` 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:*
> ```xml
> <html>
>    <image src="./foo/bar/baz.jpg" />
>    <hr />
>    <span style="color:#808080" class="hidden rounded">
>        This is coloured
>    </span>
> </html>
> ```
> will become:
> ```json
> {
>    "html": {
>        "image": {
>            "@src": "./foo/bar/baz.jpg",
>        },
>        "hr": {},
>        "span": {
>            "@style": "color:#808080",
>            "@class": "hidden rounded",
>            "keyValue": "This is coloured"
>        }
>    }
> }
> ```

---
_Source: https://npm.io/package/aft-web-services · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
