Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeroquinze/wordpress-sdk
https://github.com/zeroquinze/wordpress-sdk
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/zeroquinze/wordpress-sdk
- Owner: zeroquinze
- License: mit
- Created: 2019-05-23T11:33:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T22:29:00.000Z (almost 2 years ago)
- Last Synced: 2024-04-10T11:15:40.504Z (7 months ago)
- Language: TypeScript
- Size: 1.04 MB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [WIP] Wordpress SDK
[![npm](https://img.shields.io/npm/v/wordpress-sdk.svg)](https://www.npmjs.com/package/wordpress-sdk) [![GitHub](https://img.shields.io/github/license/iclouds/wordpress-sdk.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.org/iclouds/wordpress-sdk.svg?branch=master)](https://travis-ci.org/iclouds/wordpress-sdk)
Built with [axios](https://www.npmjs.com/package/axios), this package provides a wrapper for [Wordpress REST API](https://developer.wordpress.org/rest-api/) for fetching data from wordpress hosted sites.
## Installation
`$ npm install wordpress-sdk --save`
or if you use yarn
`$ yarn add wordpress-sdk`
## Usage
### Initializing configuration
```js
import { wordpress } from 'wordpress-sdk'
// or
const { wordpress } = require('wordpress-sdk')wordpress.initialize({
// your wordpress rest api base URL
url: 'https://developer.wordpress.org/wp-json/wp/v2',
})
```### Fetching posts
```js
wordpress
.allPosts()
.then(response => {
console.log(response.posts)
})
.catch(error => {
console.log(error.message)
})
```Or using async await
```js
try {
const { posts } = await wordpress.allPosts()
console.log(posts)
} catch (error) {
console.log(error.message)
}
```### Fetching categories
```js
wordpress
.allCategories()
.then(response => {
console.log(response.categories)
})
.catch(error => {
console.log(error.message)
})
```Or using async await
```js
try {
const { categories } = await wordpress.allCategories()
console.log(categories)
} catch (error) {
console.log(error.message)
}
```