├── .npmignore ├── .gitignore ├── .travis.yml ├── .babelrc ├── test ├── effects │ ├── removeLinks.js │ ├── liftEmbeddedAuthor.js │ ├── camelize.js │ ├── liftEmbeddedFeaturedMedia.js │ └── flattenRenderedProps.js ├── index.js └── fixtures │ └── post.js ├── src ├── effects │ ├── camelize.js │ ├── removeLinks.js │ ├── flattenRenderedProps.js │ ├── liftEmbeddedAuthor.js │ └── liftEmbeddedFeaturedMedia.js └── index.js ├── .editorconfig ├── package.json ├── LICENSE └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | !bin 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | node_modules/ 4 | coverage/ 5 | lib/ 6 | *.log 7 | bin 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | script: "npm run lint && npm run test" 5 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "node": "0.12" 6 | } 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /test/effects/removeLinks.js: -------------------------------------------------------------------------------- 1 | const merge = require('lodash.merge') 2 | 3 | const postJson = require('../fixtures/post') 4 | const effect = require('../../src/effects/removeLinks') 5 | 6 | describe('removeLinks', () => { 7 | it('transforms', () => { 8 | const result = effect(postJson, merge({}, postJson)) 9 | expect(typeof result._links).toBe('undefined') 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/effects/liftEmbeddedAuthor.js: -------------------------------------------------------------------------------- 1 | const merge = require('lodash.merge') 2 | 3 | const postJson = require('../fixtures/post') 4 | const effect = require('../../src/effects/liftEmbeddedAuthor') 5 | 6 | describe('liftEmbeddedAuthor', () => { 7 | it('transforms', () => { 8 | const result = effect(postJson, merge({}, postJson)) 9 | expect(result.author.id).toBe(42) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /test/effects/camelize.js: -------------------------------------------------------------------------------- 1 | const merge = require('lodash.merge') 2 | 3 | const postJson = require('../fixtures/post') 4 | const effect = require('../../src/effects/camelize') 5 | 6 | describe('camelize', () => { 7 | it('transforms', () => { 8 | const result = effect(postJson, merge({}, postJson)) 9 | expect(result.featuredMedia).toBeTruthy() 10 | expect(result.links).toBeTruthy() 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /src/effects/camelize.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const {camelizeKeys} = require('humps') 4 | 5 | /** 6 | * Transform all property names to camel-case. 7 | * @param {Object} original 8 | * @param {Object} flattened 9 | * @returns {Object} 10 | */ 11 | module.exports = function camelize (original, flattened) { 12 | if (!original) { 13 | return flattened 14 | } 15 | return camelizeKeys(flattened) 16 | } 17 | -------------------------------------------------------------------------------- /test/effects/liftEmbeddedFeaturedMedia.js: -------------------------------------------------------------------------------- 1 | const merge = require('lodash.merge') 2 | 3 | const postJson = require('../fixtures/post') 4 | const effect = require('../../src/effects/liftEmbeddedFeaturedMedia') 5 | 6 | describe('liftEmbeddedFeaturedMedia', () => { 7 | test('transforms', () => { 8 | const result = effect(postJson, merge({}, postJson)) 9 | expect(result.featured_media.id).toBe(15) 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /src/effects/removeLinks.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * Remove the `_links` property. 5 | * @param {Object} original 6 | * @param {Object} flattened 7 | * @returns {Object} 8 | */ 9 | module.exports = function removeLinks (original, flattened) { 10 | if (!original) { 11 | return flattened 12 | } 13 | if (typeof original._links !== 'undefined') { 14 | delete flattened._links 15 | } 16 | return flattened 17 | } 18 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | # Change these settings to your own preference 10 | indent_style = space 11 | indent_size = 2 12 | 13 | # We recommend you to keep these unchanged 14 | end_of_line = lf 15 | charset = utf-8 16 | trim_trailing_whitespace = true 17 | insert_final_newline = false 18 | 19 | [*.js] 20 | 21 | insert_final_newline = true 22 | -------------------------------------------------------------------------------- /test/effects/flattenRenderedProps.js: -------------------------------------------------------------------------------- 1 | const merge = require('lodash.merge') 2 | 3 | const postJson = require('../fixtures/post') 4 | const effect = require('../../src/effects/flattenRenderedProps') 5 | 6 | describe('flattenRenderedProps', () => { 7 | it('transforms', () => { 8 | const hasRendered = ['guid', 'title', 'content', 'excerpt'] 9 | const result = effect(postJson, merge({}, postJson)) 10 | const flattenedCount = hasRendered.reduce((i, k) => { 11 | return typeof result[k] === 'string' ? i + 1 : i 12 | }, 0) 13 | expect(flattenedCount).toBe(hasRendered.length) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /src/effects/flattenRenderedProps.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * Flatten any object that has a single property `rendered`. 5 | * @param {Object} original 6 | * @param {Object} flattened 7 | * @returns {Object} 8 | */ 9 | module.exports = function flattenRenderedProps (original, flattened) { 10 | if (!original) { 11 | return flattened 12 | } 13 | 14 | for (const key in original) { 15 | if ( 16 | typeof original[key] === 'object' 17 | && Object.keys(original[key]).length === 1 18 | && typeof original[key].rendered === 'string' 19 | ) { 20 | flattened[key] = original[key].rendered 21 | } 22 | } 23 | 24 | return flattened 25 | } 26 | -------------------------------------------------------------------------------- /src/effects/liftEmbeddedAuthor.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * Replace the author field with the embedded author entity. 5 | * @param {Object} original 6 | * @param {Object} flattened 7 | * @returns {Object} 8 | */ 9 | module.exports = function liftEmbeddedAuthor (original, flattened) { 10 | if (!original) { 11 | return flattened 12 | } 13 | 14 | if ( 15 | original.author 16 | && typeof original._embedded !== 'undefined' 17 | && Array.isArray(original._embedded.author) 18 | ) { 19 | const author = original._embedded.author.find((a) => { 20 | return a.id === original.author 21 | }) 22 | if (author) { 23 | flattened.author = author 24 | } 25 | } 26 | 27 | return flattened 28 | } 29 | -------------------------------------------------------------------------------- /src/effects/liftEmbeddedFeaturedMedia.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const find = require('lodash.find') 4 | 5 | const fmKey = 'wp:featuredmedia' 6 | 7 | /** 8 | * Replace the `featured_media` field with the value of the embedded `wp:featuredmedia`. 9 | * @param {Object} original 10 | * @param {Object} flattened 11 | * @returns {Object} 12 | */ 13 | module.exports = function liftEmbeddedFeaturedMedia (original, flattened) { 14 | if (!original) { 15 | return flattened 16 | } 17 | 18 | const hasFeaturedMedia = original.featured_media 19 | const hasEmbeddedFeaturedMedia = original._embedded && original._embedded[fmKey] 20 | 21 | if (hasEmbeddedFeaturedMedia && hasFeaturedMedia) { 22 | flattened.featured_media = find(flattened._embedded[fmKey], (media) => { 23 | return media.id === original.featured_media 24 | }) 25 | } 26 | 27 | return flattened 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wp-api-response-modify", 3 | "version": "3.0.0", 4 | "description": "Makes WP API response JSON sensible", 5 | "main": "bin/index.js", 6 | "jsnext:main": "src/index.js", 7 | "scripts": { 8 | "lint": "standard src/*", 9 | "test": "jest", 10 | "build": "babel src --out-dir bin", 11 | "prepublishOnly": "npm run lint && npm test && npm run build" 12 | }, 13 | "dependencies": { 14 | "humps": "^1.0.0", 15 | "lodash.find": "^4.4.0", 16 | "lodash.merge": "^4.4.0", 17 | "lodash.values": "^4.3.0" 18 | }, 19 | "devDependencies": { 20 | "babel": "^6.23.0", 21 | "babel-cli": "^6.26.0", 22 | "babel-core": "^6.26.0", 23 | "babel-preset-env": "^1.6.0", 24 | "jest": "^21.1.0", 25 | "standard": "^7.1.2" 26 | }, 27 | "jest": { 28 | "testRegex": "test", 29 | "testPathIgnorePatterns": [ 30 | "fixtures" 31 | ] 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Outlandish 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const merge = require('lodash.merge') 4 | const values = require('lodash.values') 5 | 6 | module.exports = modify 7 | 8 | const effectsHash = module.exports.effects = { 9 | removeLinks: require('./effects/removeLinks'), 10 | flattenRenderedProps: require('./effects/flattenRenderedProps'), 11 | liftEmbeddedAuthor: require('./effects/liftEmbeddedAuthor'), 12 | liftEmbeddedFeaturedMedia: require('./effects/liftEmbeddedFeaturedMedia'), 13 | // Perform last so effects always handle raw property names 14 | camelize: require('./effects/camelize') 15 | } 16 | 17 | /** 18 | * Make a WP API response JSON sensible. 19 | * @param {Object|Array} response WP API response JSON 20 | * @param {Array} [effects] Effects to apply to the response, defaults to all effects 21 | * @returns {Object} Modified response JSON 22 | */ 23 | function modify (response, effects = values(effectsHash)) { 24 | if (!Array.isArray(effects)) { 25 | throw new Error(`Expecting effects to be an array, got "${typeof effects}".`) 26 | } else if (!response || typeof response !== 'object') { 27 | throw new Error(`Expecting response to be an array or object, got "${typeof response}".`) 28 | } 29 | 30 | response = Array.isArray(response) 31 | ? response.map((r) => modify(r, effects)) : response 32 | 33 | return effects.reduce((flattened, effect) => { 34 | if (typeof effect !== 'function') { 35 | throw new Error('Effect is not a function') 36 | } 37 | return effect(response, flattened) 38 | }, merge({}, response)) 39 | } 40 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const postJson = require('./fixtures/post') 2 | const modify = require('../src') 3 | 4 | describe('wp-api-response-modifier', () => { 5 | it('throws with bad response', () => { 6 | expect(() => modify(1, [])).toThrowError(/expecting response to be/i) 7 | expect(() => modify(null, [])).toThrowError(/expecting response to be/i) 8 | expect(() => modify("", [])).toThrowError(/expecting response to be/i) 9 | }) 10 | 11 | it('throws if effects is not function or array', () => { 12 | expect(() => modify(postJson, 1)).toThrowError(/expecting effects to be/i) 13 | }) 14 | 15 | it('throws if an effect is not a function', () => { 16 | expect(() => modify(postJson, [() => {}, 1])).toThrowError(/effect is not a function/i) 17 | }) 18 | 19 | it('does not throw if effects not given', () => { 20 | expect(() => modify(postJson)).not.toThrow() 21 | }) 22 | 23 | it('accepts effects fn', () => { 24 | const hasRendered = ['guid', 'title', 'content', 'excerpt'] 25 | const result = modify(postJson, [modify.effects.flattenRenderedProps]) 26 | const flattenedCount = hasRendered.reduce((i, k) => { 27 | return typeof result[k] === 'string' ? i + 1 : i 28 | }, 0) 29 | 30 | // Check given effect was applied 31 | expect(flattenedCount).toEqual(hasRendered.length) 32 | // Check `_links` is still here, which means override of effects was successful 33 | expect(typeof result._links).toEqual('object') 34 | }) 35 | 36 | it('accepts effects array', () => { 37 | const result = modify(postJson, [ 38 | modify.effects.removeLinks, 39 | modify.effects.camelize 40 | ]) 41 | 42 | expect(typeof result._links).toEqual('undefined') 43 | expect(result.featuredMedia).toBeTruthy() 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wp-api-response-modify 2 | 3 | > Makes WP API response JSON sensible 4 | 5 | Made with ❤ at [@outlandish](http://www.twitter.com/outlandish) 6 | 7 | npm version 8 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) 9 | 10 | Makes response JSON from the WP API sensible. By default it... 11 | 12 | - transforms properties to camel-case 13 | - flattens objects with a single property `rendered` 14 | - lifts embedded entities (author, featured media, etc.) 15 | - removes the `_links` property 16 | 17 | See the [list of effects](#effects) for more. 18 | 19 | ## Install 20 | 21 | ```sh 22 | npm install --save wp-api-response-modify 23 | ``` 24 | 25 | ## Import 26 | 27 | ```js 28 | // ES2015 29 | import modify from 'wp-api-response-modify' 30 | 31 | // CommonJS 32 | var modify = require('wp-api-response-modify') 33 | ``` 34 | 35 | ## Usage 36 | 37 | ### `modify(response[, effects]) : Object` 38 | 39 | Make a WP API response sensible. 40 | 41 | - __response__ {Object} Response from WP-API 42 | - [__effects__] {Array} _(optional)_ Effects to apply to the response 43 | 44 | Returns the modified response. 45 | 46 | ## Effects 47 | 48 | All effects are available at `modify.effects`, e.g. `modify.effects.flattenRenderedProps`. 49 | 50 | Example: `featured_media => featuredMedia` 51 | 52 | ### `flattenRenderedProps` 53 | 54 | Flatten any object that has a single property `rendered`. 55 | 56 | Example: 57 | 58 | ```js 59 | { content: { rendered: 'content string' } } 60 | // becomes... 61 | { content: 'content string' } 62 | ``` 63 | 64 | ### `liftEmbeddedAuthor` 65 | 66 | Replace the author field with the embedded author entity. 67 | 68 | Example: 69 | 70 | ```js 71 | { author: 12, _embedded: { author: { id: 12, ... } } } 72 | // becomes... 73 | { author: { id: 12, ... } } 74 | ``` 75 | 76 | ### `liftEmbeddedFeaturedMedia` 77 | 78 | Replace the `featured_media` field with the value of the embedded `wp:featuredmedia`. 79 | 80 | ### `removeLinks` 81 | 82 | Remove the `_links` property. 83 | 84 | ### `camelize` 85 | 86 | Transform all property names to camel-case in the response. 87 | 88 | ## Contributing 89 | 90 | All pull requests and issues welcome! 91 | 92 | If you're not sure how, check out Kent C. Dodds' 93 | [great video tutorials on egghead.io](https://egghead.io/lessons/javascript-identifying-how-to-contribute-to-an-open-source-project-on-github)! 94 | 95 | ## Author & License 96 | 97 | `wp-api-response-modify` was created by [Outlandish](https://twitter.com/outlandish) and is released under the MIT license. 98 | -------------------------------------------------------------------------------- /test/fixtures/post.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'id': 16, 3 | 'date': '2015-12-31T14:51:26', 4 | 'date_gmt': '2015-12-31T14:51:26', 5 | 'guid': { 6 | 'rendered': 'http://wp-api-de-elbinsta-n5pu020s13lb-1748419096.eu-west-1.elb.amazonaws.com/?p=16' 7 | }, 8 | 'modified': '2015-12-31T14:51:26', 9 | 'modified_gmt': '2015-12-31T14:51:26', 10 | 'slug': 'architecto-enim-omnis-repellendus', 11 | 'type': 'post', 12 | 'link': 'http://demo.wp-api.org/2015/12/31/architecto-enim-omnis-repellendus/', 13 | 'title': { 14 | 'rendered': 'Architecto enim omnis repellendus' 15 | }, 16 | 'content': { 17 | 'rendered': '
Similique eaque voluptas cum voluptatem. Similique debitis quis sapiente veniam saepe. Architecto qui repellendus autem dolor autem est molestiae
\n

\'Molestiae

\n
    \n
  1. Libero ut
  2. \n
  3. Libero sunt nihil laboriosam rerum
  4. \n
  5. Rem modi
  6. \n
  7. Quod minus est nam alias velit
  8. \n
  9. Id consequatur doloribus sed et
  10. \n
  11. Maiores nulla eveniet
  12. \n
  13. Ut voluptates accusamus voluptas ea
  14. \n
  15. Quia esse id temporibus et et maiores
  16. \n
\n

Voluptatem qui eveniet quidem quia rerum voluptatem. Vel ipsa provident nesciunt at. Sed velit et placeat et et

\n\n

Iste velit in modi. Officia rerum error et quo molestiae. Reiciendis est est libero recusandae quia earum

\n
\n
\n
Earum harum non magni placeat rerum velit dolore. Et non facilis eum quidem vero beatae corrupti in. Repellendus ut et nobis
\n

Nobis est voluptatem ipsum sunt veniam. Iusto quia mollitia sed at non. Corrupti quibusdam et doloremque sed. similique sint Ut modi neque nostrum molestiae aut. officiis id dolores numquam. Error voluptate eum quasi cum. Rerum inventore cupiditate magni inventore magnam Magnam omnis necessitatibus veritatis modi. inventore accusamus sit sapiente expedita nam eos.

\n
Qui blanditiis et dolorum veniam alias aperiam. Hic quisquam neque ea alias nostrum voluptas
\n\n

Corporis quasi ut magnam omnis. Accusantium quasi doloremque quia quas quasi modi mollitia consequatur. Eligendi rerum repellendus mollitia iste. Architecto neque eveniet laborum iste suscipit quod aut. Nam vero rerum fugit delectus qui dolores consequatur. Porro molestiae unde voluptatum laudantium. Autem distinctio ducimus enim qui. Fugit possimus eos qui aliquid accusamus magnam. Consequatur iusto non quibusdam sapiente modi deserunt. Velit et dicta iusto est natus. Eligendi ut officiis et quasi. Nihil voluptatum facere dolores quae voluptatem. Sunt sed ex provident et quam. Molestiae aut et eveniet tempore. Voluptas est quia nobis temporibus natus sint. Autem animi et accusamus quidem occaecati dolorem impedit accusantium. Quibusdam quis omnis provident alias voluptatem. Quisquam impedit quos est tenetur animi ipsam. Recusandae aut incidunt ex minima quisquam ea quia. Quod blanditiis nulla qui maxime nemo corrupti. Itaque est voluptate voluptatem voluptates rerum quasi dolor. Autem illo cumque voluptatem pariatur repellendus commodi illum dolorem. Quidem totam ut neque praesentium. Debitis ut est eveniet itaque repellat. In labore et et quia qui aut dolor. Illum rerum magni quia porro quae et fugiat. Esse dolore sint minima possimus sed ut. Ut harum sequi corrupti. Velit distinctio eum ullam corrupti dolorem earum eum. Rerum impedit iure omnis nesciunt. Quisquam voluptatem consequatur quia. Est ab quae cum ut. Nihil quidem iste est reiciendis quisquam ut. Consequatur dolorum consequatur modi. Porro cupiditate nostrum quam recusandae unde. Autem dolorem nemo nesciunt id praesentium exercitationem aut. Eos magni natus sit dolores dolorum animi assumenda aliquid. Id cupiditate nobis officiis totam. Eveniet dolores cum voluptas quam. Ut vel est velit at et aut velit. Quod sed nam in ut sit hic.

\n

Quibusdam consectetur illum quis id rerum. Ea est ut autem consequatur earum

\n

\'Nisi

\n
    \n
  1. Consequatur qui qui est modi
  2. \n
  3. Ipsam quasi ex
  4. \n
  5. Necessitatibus quia sequi non saepe
  6. \n
  7. Eum dignissimos voluptas vel qui similique
  8. \n
  9. Quo laborum
  10. \n
  11. Quidem delectus autem aut sit voluptatem
  12. \n
  13. Voluptates qui reiciendis atque minus ipsam perferendis
  14. \n
  15. Enim hic quas explicabo
  16. \n
  17. Vel explicabo suscipit laudantium
  18. \n
  19. Ut ut sed eum culpa nesciunt quis quis
  20. \n
  21. Enim laborum voluptatem dolorem est inventore
  22. \n
\n
Omnis quam in reprehenderit. Porro magni voluptatem aut adipisci quia aut ea optio. Rem qui esse dolorem porro eveniet qui
\n\n

Voluptatibus aliquam expedita repudiandae rerum consequuntur fuga. Provident voluptatem autem vel sit

\n

Est unde voluptatum illum Est similique maiores omnis facere est molestiae. Sunt ut itaque omnis non. Dolore perspiciatis iste et veniam eius. Ipsum est similique consequatur. Magnam ea ex saepe dolor corrupti. Quia fuga qui ex. beatae placeat non Omnis possimus voluptate ea quia enim. et suscipit magni est illo. Qui totam vitae tenetur quos reprehenderit.

\n' 18 | }, 19 | 'excerpt': { 20 | 'rendered': '

Similique eaque voluptas cum voluptatem. Similique debitis quis sapiente veniam saepe. Architecto qui repellendus autem dolor autem est molestiae Libero ut Libero sunt nihil laboriosam rerum Rem modi Quod minus est nam alias velit Id consequatur doloribus sed et Maiores nulla eveniet Ut voluptates accusamus voluptas ea Quia esse id temporibus et et maiores Voluptatem […]

\n' 21 | }, 22 | 'author': 42, 23 | 'featured_media': 15, 24 | 'comment_status': 'open', 25 | 'ping_status': 'open', 26 | 'sticky': false, 27 | 'format': 'standard', 28 | 'categories': [1], 29 | 'tags': [], 30 | '_links': { 31 | 'self': [{ 32 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/posts/16' 33 | }], 34 | 'collection': [{ 35 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/posts' 36 | }], 37 | 'about': [{ 38 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/types/post' 39 | }], 40 | 'author': [{ 41 | 'embeddable': true, 42 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/users/42' 43 | }], 44 | 'replies': [{ 45 | 'embeddable': true, 46 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/comments?post=16' 47 | }], 48 | 'version-history': [{ 49 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/posts/16/revisions' 50 | }], 51 | 'wp:featuredmedia': [{ 52 | 'embeddable': true, 53 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/media/15' 54 | }], 55 | 'wp:attachment': [{ 56 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/media?parent=16' 57 | }], 58 | 'wp:term': [{ 59 | 'taxonomy': 'category', 60 | 'embeddable': true, 61 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/categories?post=16' 62 | }, 63 | { 64 | 'taxonomy': 'post_tag', 65 | 'embeddable': true, 66 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/tags?post=16' 67 | }], 68 | 'curies': [{ 69 | 'name': 'wp', 70 | 'href': 'https://api.w.org/{rel}', 71 | 'templated': true 72 | }] 73 | }, 74 | '_embedded': { 75 | 'author': [{ 76 | 'id': 42, 77 | 'name': 'Sophia', 78 | 'url': 'http://Little.com/fugit-rem-in-consequuntur-perspiciatis-ex', 79 | 'description': 'Cumque esse consequatur facere minus. In tenetur culpa illo sint labore nostrum quis. Explicabo animi explicabo perferendis nesciunt omnis quo sunt nihil. Quod magnam necessitatibus dicta amet omnis aliquid.\r\n\r\nEt dolor consequuntur necessitatibus sequi incidunt est ratione. Unde sint iusto possimus officiis cum molestiae. Nostrum ad illo pariatur et.\r\n\r\nDoloremque neque doloremque voluptas vel voluptas placeat est. Consectetur qui et accusamus.\r\n\r\nCorrupti qui accusamus voluptatum ab architecto sapiente fugit quis. Ut et sit quod ea voluptates nobis. Enim qui eos magnam at.\r\n\r\nQuia error tempora ullam nulla illo sint. Velit perferendis amet facere quia dignissimos. Rerum nihil pariatur eum velit rerum.\r\n\r\nVelit laudantium voluptate nesciunt et cupiditate asperiores. Voluptatem recusandae numquam et neque unde molestiae voluptate. Rerum et harum occaecati quis occaecati voluptas. Sequi qui dolores cumque nostrum ab nostrum.\r\n\r\nExplicabo cum voluptates odit asperiores ut. Ipsam exercitationem eum nostrum qui dolorum sint nulla. Aut perferendis dolorem ab itaque architecto ad enim.\r\n\r\nMinima aut nobis qui enim beatae. Quis quo modi nemo est quam ea inventore. Odit consequatur vitae perferendis mollitia pariatur voluptas ea sit.\r\n\r\nIn qui saepe ducimus labore. Perferendis ducimus quia corporis perspiciatis. Autem nobis explicabo debitis laboriosam tempora aut.', 80 | 'link': 'http://demo.wp-api.org/author/meaghan-willms/', 81 | 'slug': 'meaghan-willms', 82 | 'avatar_urls': { 83 | '24': 'http://2.gravatar.com/avatar/bf432d6e226ae2f791a59ddd2b3f8462?s=24&d=mm&r=g', 84 | '48': 'http://2.gravatar.com/avatar/bf432d6e226ae2f791a59ddd2b3f8462?s=48&d=mm&r=g', 85 | '96': 'http://2.gravatar.com/avatar/bf432d6e226ae2f791a59ddd2b3f8462?s=96&d=mm&r=g' 86 | }, 87 | '_links': { 88 | 'self': [{ 89 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/users/42' 90 | }], 91 | 'collection': [{ 92 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/users' 93 | }] 94 | } 95 | }], 96 | 'wp:featuredmedia': [{ 97 | 'id': 15, 98 | 'date': '2015-06-03T22:18:52', 99 | 'slug': 'vero-amet-id-commodi-harum', 100 | 'type': 'attachment', 101 | 'link': 'http://demo.wp-api.org/vero-amet-id-commodi-harum/', 102 | 'title': { 103 | 'rendered': 'Vero amet id commodi harum' 104 | }, 105 | 'author': 100, 106 | 'alt_text': '', 107 | 'media_type': 'image', 108 | 'mime_type': 'image/jpeg', 109 | 'media_details': { 110 | 'width': 1080, 111 | 'height': 631, 112 | 'file': '2015/06/0845fa5d-4c5e-3c93-a054-63a976339952.jpg', 113 | 'sizes': { 114 | 'thumbnail': { 115 | 'file': '0845fa5d-4c5e-3c93-a054-63a976339952-150x150.jpg', 116 | 'width': 150, 117 | 'height': 150, 118 | 'mime_type': 'image/jpeg', 119 | 'source_url': 'http://demo.wp-api.org/content/uploads/2015/06/0845fa5d-4c5e-3c93-a054-63a976339952-150x150.jpg' 120 | }, 121 | 'medium': { 122 | 'file': '0845fa5d-4c5e-3c93-a054-63a976339952-300x175.jpg', 123 | 'width': 300, 124 | 'height': 175, 125 | 'mime_type': 'image/jpeg', 126 | 'source_url': 'http://demo.wp-api.org/content/uploads/2015/06/0845fa5d-4c5e-3c93-a054-63a976339952-300x175.jpg' 127 | }, 128 | 'large': { 129 | 'file': '0845fa5d-4c5e-3c93-a054-63a976339952-1024x598.jpg', 130 | 'width': 1024, 131 | 'height': 598, 132 | 'mime_type': 'image/jpeg', 133 | 'source_url': 'http://demo.wp-api.org/content/uploads/2015/06/0845fa5d-4c5e-3c93-a054-63a976339952-1024x598.jpg' 134 | }, 135 | 'full': { 136 | 'file': '0845fa5d-4c5e-3c93-a054-63a976339952.jpg', 137 | 'width': 1080, 138 | 'height': 631, 139 | 'mime_type': 'image/jpeg', 140 | 'source_url': 'http://demo.wp-api.org/content/uploads/2015/06/0845fa5d-4c5e-3c93-a054-63a976339952.jpg' 141 | } 142 | }, 143 | 'image_meta': { 144 | 'aperture': 0, 145 | 'credit': 'JOKINROM', 146 | 'camera': '', 147 | 'caption': '', 148 | 'created_timestamp': 1430341682, 149 | 'copyright': '', 150 | 'focal_length': 0, 151 | 'iso': 0, 152 | 'shutter_speed': 0, 153 | 'title': '', 154 | 'orientation': 0 155 | } 156 | }, 157 | 'source_url': 'http://demo.wp-api.org/content/uploads/2015/06/0845fa5d-4c5e-3c93-a054-63a976339952.jpg', 158 | '_links': { 159 | 'self': [{ 160 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/media/15' 161 | }], 162 | 'collection': [{ 163 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/media' 164 | }], 165 | 'about': [{ 166 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/types/attachment' 167 | }], 168 | 'author': [{ 169 | 'embeddable': true, 170 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/users/100' 171 | }], 172 | 'replies': [{ 173 | 'embeddable': true, 174 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/comments?post=15' 175 | }] 176 | } 177 | }], 178 | 'wp:term': [[{ 179 | 'id': 1, 180 | 'link': 'http://demo.wp-api.org/category/uncategorized/', 181 | 'name': 'Uncategorized', 182 | 'slug': 'uncategorized', 183 | 'taxonomy': 'category', 184 | '_links': { 185 | 'self': [{ 186 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/categories/1' 187 | }], 188 | 'collection': [{ 189 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/categories' 190 | }], 191 | 'about': [{ 192 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/taxonomies/category' 193 | }], 194 | 'wp:post_type': [{ 195 | 'href': 'http://demo.wp-api.org/wp-json/wp/v2/posts?categories=1' 196 | }], 197 | 'curies': [{ 198 | 'name': 'wp', 199 | 'href': 'https://api.w.org/{rel}', 200 | 'templated': true 201 | }] 202 | } 203 | }], 204 | []] 205 | } 206 | } 207 | --------------------------------------------------------------------------------