Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/outlandishideas/wp-api-response-modify
Makes WP API response JSON sensible
https://github.com/outlandishideas/wp-api-response-modify
Last synced: about 1 month ago
JSON representation
Makes WP API response JSON sensible
- Host: GitHub
- URL: https://github.com/outlandishideas/wp-api-response-modify
- Owner: outlandishideas
- License: mit
- Archived: true
- Created: 2016-07-25T09:49:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-17T10:57:14.000Z (over 7 years ago)
- Last Synced: 2024-06-26T12:40:03.687Z (6 months ago)
- Language: JavaScript
- Size: 54.7 KB
- Stars: 8
- Watchers: 8
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wp-developer-tools - WP-API Response Modify - Makes response JSON from the WP API sensible. (WordPress Plugins)
README
# wp-api-response-modify
> Makes WP API response JSON sensible
Made with ❤ at [@outlandish](http://www.twitter.com/outlandish)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)Makes response JSON from the WP API sensible. By default it...
- transforms properties to camel-case
- flattens objects with a single property `rendered`
- lifts embedded entities (author, featured media, etc.)
- removes the `_links` propertySee the [list of effects](#effects) for more.
## Install
```sh
npm install --save wp-api-response-modify
```## Import
```js
// ES2015
import modify from 'wp-api-response-modify'// CommonJS
var modify = require('wp-api-response-modify')
```## Usage
### `modify(response[, effects]) : Object`
Make a WP API response sensible.
- __response__ {Object} Response from WP-API
- [__effects__] {Array} _(optional)_ Effects to apply to the responseReturns the modified response.
## Effects
All effects are available at `modify.effects`, e.g. `modify.effects.flattenRenderedProps`.
Example: `featured_media => featuredMedia`
### `flattenRenderedProps`
Flatten any object that has a single property `rendered`.
Example:
```js
{ content: { rendered: 'content string' } }
// becomes...
{ content: 'content string' }
```### `liftEmbeddedAuthor`
Replace the author field with the embedded author entity.
Example:
```js
{ author: 12, _embedded: { author: { id: 12, ... } } }
// becomes...
{ author: { id: 12, ... } }
```### `liftEmbeddedFeaturedMedia`
Replace the `featured_media` field with the value of the embedded `wp:featuredmedia`.
### `removeLinks`
Remove the `_links` property.
### `camelize`
Transform all property names to camel-case in the response.
## Contributing
All pull requests and issues welcome!
If you're not sure how, check out Kent C. Dodds'
[great video tutorials on egghead.io](https://egghead.io/lessons/javascript-identifying-how-to-contribute-to-an-open-source-project-on-github)!## Author & License
`wp-api-response-modify` was created by [Outlandish](https://twitter.com/outlandish) and is released under the MIT license.