I’ll continue my previous articles about Consuming WordPress JSON API, Tags and Categories by showing you how to Grab the Media (probably mostly Images) from the JSON API of a WordPress Web Site. The Endpoint for Images is: https://<wp>/wp-json/wp/v2/media?[offset=<0,10,20>]. It has the following – more complex Data Model:
Important and probably most used fields of this complex object are:
- media_type – what it the type of the WordPress Media content
- mime_type may be useful in some scenarios for more technical and detail functionality or requirements.
- source_url – the URL for the best Quality
- alt_text – the hint/tooltip/title used in browsers and in mobile applications to indicate what is the image about. Adding this property to images is a must for greater accessibility. In some situations the images are not displayed so, alt attribute is considered required.
- post – if the image is a logo of some article
- author – the WP User that has uploaded the image
- date/date_gmt/modified/modified_gmt – dates of creation or modification
- There is a media_details object containing width and height fields – that show how big is the original content [for images].
- The JSON contains several identical objects in the “sizes” sub-object of media_details. They store the thumbnails of the image for the different locations and sizes.
- The JSON contains several identical objects in the “sizes” sub-object of media_details. They store the thumbnails of the image for the different locations and sizes.
You could open a Flutter Web Application that loads the last 10 images from this site – on this address: https://programtom.com/dev_examples/wp_media/.