https://github.com/jaredreisinger/wordpressed
A modern, Typescript+ESM client for the WordPress REST API.
https://github.com/jaredreisinger/wordpressed
Last synced: about 1 year ago
JSON representation
A modern, Typescript+ESM client for the WordPress REST API.
- Host: GitHub
- URL: https://github.com/jaredreisinger/wordpressed
- Owner: JaredReisinger
- License: isc
- Created: 2023-07-17T04:07:47.000Z (almost 3 years ago)
- Default Branch: alpha
- Last Pushed: 2024-09-16T23:18:11.000Z (over 1 year ago)
- Last Synced: 2024-10-15T02:34:58.169Z (over 1 year ago)
- Language: TypeScript
- Size: 1.98 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Roadmap: docs/ROADMAP.md
Awesome Lists containing this project
README
# wordpressed
A modern, Typescript+ESM client for the WordPress REST API. _(Rhymes with “wordpREST”!)_
[](https://www.npmjs.com/package/wordpressed)
[](https://github.com/JaredReisinger/wordpressed/actions?query=workflow%3Abuild+branch%3Aalpha)
[](https://codecov.io/github/JaredReisinger/wordpressed)
[](https://snyk.io/test/github/JaredReisinger/wordpressed/alpha)
> **WARNING:** This is _**very much**_ an early work-in-progress. It is being published so that early feedback on design decisions can be made. There _**will**_ be changes to the way that calls/requests are made.
## Usage
Just construct the client with the URL to your WordPress host, and start making REST API calls with the `get()`, `post()`, `delete()`, etc. method-specific functions:
```ts
import { Client } from 'wordpressed';
const client = new Client('http://myhost.example.org');
const response = await client.get('/wp/v2/pages', {
after: '2023-08-01T00:00:00Z',
per_page: 100,
});
response.body.forEach((page => { ... })
```
Note that you get Typescript type checking and intellisense completion (if your editor supports it) on the routes, the arguments specific to that route, and for the response body:

## What to do if your routes aren’t included
If you have a use-case that involves a plugin/namespace/routes/endpoints that aren’t already a part of this library, you can use the included [`wordpressed` CLI](https://github.com/JaredReisinger/wordpressed/blob/alpha/docs/cli/README.md) to generate your own custom types, and then provide those to your client instance.
See the [_Customizing_ section of the type-generation docs](https://github.com/JaredReisinger/wordpressed/blob/alpha/docs/type-generation.md#customizing) for all the details.
## It’s _much_ smaller than it looks!
As of 2023–08–09, `npm pack --dry-run` on my machine reports about 850kB in file size, which matches the “unpacked size” reported on npmjs.com. But 775kB (_**91%!**_) of that is the `namespace` directory, which is entirely Typescript types that only exist at edit/build time. If you are including this library and running any kind of bundler/transpiler, you will likely end up with _at most_ 32kB (3.8% of the package) of `.js` files included from this library in your final build.
So yes, it’s a relatively sizeable package for the runtime functionality. But the whole point of this is that 91% set of types that drastically improves the edit-time experience. As time goes on and more types come in, that proportion is likely to grow… but the actual run-time impact of the package will remain unchanged.