
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
wordpress-api-client
Advanced tools
A typed JavaScript client for your WordPress REST API. Super simple yet highly extensible.
This library covers all built-in WP REST API routes and can easily be extended with custom routes. Fully integrated with Advanced Custom Fields.
Depending on the package manager of your choice:
yarn add wordpress-api-client
npm install wordpress-api-client
If you only need to access public REST routes from a vanilla WordPress installation, all you need is:
import WpApiClient from 'wordpress-api-client'
export const client = new WpApiClient('https://my-wordpress-website.com')
The next example shows how this bare setup, from above, will already cover most of your needs:
import WpApiClient, { WPCategory, WPPage, WPPost } from 'wordpress-api-client'
async function getContent(): Promise<{
aboutPage: WPPage
contactPage: WPPage
frontPage: WPPage
categories: WPCategory[]
recent25posts: WPPost[]
}> {
const client = new WpApiClient('https://my-wordpress-website.com')
const [aboutPage, contactPage, frontPage] = await client.page().find(12, 23, 34)
const categories = await client.postCategory().find()
const recent25posts = await client.posts().find(new URLSearchParams({
order: 'desc',
per_page: '25',
}))
return { frontPage, aboutPage, contactPage, categories, recent25Posts }
}
If you would like to extend the client, adding post types and REST end points is as easy as you would expect (example from the demo project):
import { CustomPost, WPMenu, WPProduct } from './types'
import WpApiClient, { DefaultEndpointWithRevision } from 'wordpress-api-client'
const EP_PRODUCTS = 'wp/v2/products'
const EP_MENU = 'demo-plugin/v1/menu'
export class WpClient extends WpApiClient {
constructor() {
super('http://localhost:8080', {
auth: {
type: 'basic',
password: 'password',
username: 'admin',
},
})
}
post<P = CustomPost>(): DefaultEndpointWithRevision<P> {
return super.post<P>()
}
public product(): DefaultEndpointWithRevision<WPProduct> {
return this.addPostType<WPProduct>(EP_PRODUCTS, true)
}
menu = this.createEndpointCustomGet<WPMenu>(EP_MENU)
}
With this WpClient
class, extended from this package's WpApiClient
class,
you have full access to your WordPress's REST API, including your custom post
types, custom end points and Advanced Custom Fields:
import { WpClient } from './wp-client'
const client = new WpClient()
// custom end points
await client.menu()
await client.product().find()
await client.product().create()
await client.product().update()
await client.product().delete()
await client.product().revision().find()
await client.product().revision().create()
await client.product().revision().update()
await client.product().revision().delete()
// default end points
await client.siteSettings.find()
await client.taxonomy().find()
await client.page().find()
await client...
Feel free to report an issue if you are having trouble and the documentation is not helping.
Damian 💻 📖 💡 🚧 ⚠️ | Jon Wolfe 💻 🤔 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Please fork the upstream repository into your own account and apply your changes to a new branch. Make sure to add tests, if necessary, before opening a PR against the upstream main-branch.
Comment on an issue or on a PR and the all-contributors bot will add you to the list above :)
FAQs
WordPress-API Client for JS/TS
The npm package wordpress-api-client receives a total of 16 weekly downloads. As such, wordpress-api-client popularity was classified as not popular.
We found that wordpress-api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.