# pp-wapi

> A wordpress api client

Latest version **0.4.3** (published 2019-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install pp-wapi
pnpm add pp-wapi
yarn add pp-wapi
bun add pp-wapi
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2019-02-13 |
| First published | 2018-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Simon Leigh |
| Maintainers | butterycrumpet |

## Links

- npm: https://www.npmjs.com/package/pp-wapi
- Repository: https://github.com/ButteryCrumpet/wordpress-api-client
- Homepage: https://github.com/ButteryCrumpet/wordpress-api-client#readme
- Issues: https://github.com/ButteryCrumpet/wordpress-api-client/issues
- npm.io page: https://npm.io/package/pp-wapi

## Recent versions

- 0.4.3 (latest) — 2019-02-13
- 0.4.2 — 2019-02-12
- 0.4.1 — 2019-01-25
- 0.4.0 — 2018-10-19
- 0.3.1 — 2018-10-19
- 0.3.0 — 2018-10-19
- 0.2.0 — 2018-10-18
- 0.0.1 — 2018-10-18

## README

A Wordpress api client
======================

## Description

A very simple Javascript client for accessing a Wordpress site's API \
Currently only offers access to Posts and Terms following the standard schema \
(very unstable)

## Documentation

1. Instantiate a WPClient instance passing in your wordpress site's url
2. Call either WPClient::getPosts or WPClient::getTerms passing in a callback and args
3. Receive Result<WPResponse<T>, Err> and check with isOk / isErr or unwrap() to get value

A WPResponse contains meta data about the query as well as the received content
```typescript
interface WPResponse<T> {
    meta: QueryMeta
    content: T // currently either BasicPost[] or Term[]
}

// not in all queries so possibility to be undefined, will move to Maybe<T> in the future
interface QueryMeta {
  count: number | undefined,
  totalPages: number | undefined
}

```

### -- Notes

* Currently getPosts and getTerms are *curried* 
    * To call them either pass in callback then args like so: 
        ```typescript
        WPClient::getPosts(callback)(args)
        ``` 
    * Or save to a variable: 
        ```typescript
        const query = WPClient::getPosts(callback)
        query(args)
        ``` 
* Uses fetch and promises, use polyfills if supporting legacy browsers
* Caches fetch requests in memory during a session

### -- Example

```typescript
import { WPClient, unwrap } from "pp-wapi"

// Instantiate client
const client = new WPClient("www.testwp.com")

// Callback to run on request completion
const callback = result => console.log(unwrap(result))

// Post query args, see below for list of possible values
const args = {
    page: 2,
    categories: [ 1, 4 ]
}
client.getPosts(callback)(args)

```

### -- Post Query Possible Args

```typescript
interface PostQueryArgs {
  type?: string
  page?: number
  per_page?: number
  p?: number
  slug?: string
  search?: string
  after?: string
  categories?: number[]
  categories_exclude?: number[]
  tags?: number[]
  tags_exclude?: number[]
  author?: number[]
  author_exclude?: number[]
  exclude?: number[]
  include?: number[]
  offset?: number
  order?: Order
  orderby?: PostOrderBy
  status?: string
}
```

### -- Term Query Possible Args

```typescript
interface TermQueryArgs {
  type: string
  term_id?: number
  page?: number
  per_page?: number
  search?: string
  exclude?: number[]
  include?: number[]
  order?: Order
  orderby?: TermOrderBy
  hide_empty?: boolean
  parent?: number
  slug?: string
}
```

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