LD09: APIs due Tue 24 Oct 14:45

Preparation for Lab Day

To prepare for lab day make sure the API for your blog.yourdomain Wordpress install is working. Visit https://blog.yourdomain/wp-json/wp/v2. This will likely produce a 404 (page not found) response. If that is the case you'll need to follow the instructions below. If it happens to produce a large block of JSON text then you can skip the remaining steps.
  1. Make sure mod_rewrite is installed in apache: sudo a2enmod rewrite
  2. In Wordpress go to the dashboard -> Settings -> Permalinks. Make sure index.php is removed from the URL.
  3. Edit your the SSL version of your blog.yourdomain.conf to add lines similar to these:
    <Directory "/var/www/live/blog.yourdomain/wordpress">
        DirectoryIndex index.php
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
            RewriteRule ^index\.php$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.php [L]

  4. Restart apache
  5. Revisit the URL in your browser and verify you now get a JSON response.
  6. We'll make use of your favoite JSON tool, jq, again, so make sure it is installed. sudo apt install jq
  7. Test the install from browser and using curl from the command-line:
    curl https://blog.yourdomain/wp-json/wp/v2    # a wall of JSON code
    curl https://blog.yourdomain/wp-json/wp/v2 | jq . -C   # pretty JSON w/ colors
    curl https://blog.yourdomain/wp-json/wp/v2 | jq . -C | less -R  # pretty & scrollable

Now that the API is configured and working take a moment to read through this site which gives very helpful examples of using jq:


Lab Day

Begin working through the instructions given for Homework #9