Creating an automatically updating news page
- A JSON document database is a natural fit for storing news article information.
- HTTP based API to update and access database
- DBaaS - no servers to maintain, quick and easy setup
Getting started Cloudant on BlueMix
- Create a BlueMix account
- Find the Cloudant service
- Select a Cloudant plan
- Add Cloudant to your BlueMix
Create your BlueMix account
You will need to register to get started with BlueMix. Click here to create a BlueMix account.
Find the Cloudant Service
- Select catalog from the top navigation bar
- Check Data and Analytics on the filter on the left navigation bar.
You should see a screen like this
Select Cloudant NoSQL DB Service
Select Cloudant Plan
From here, you can add and configure the Cloudant service. I left all the default values and clicked create.
Add Cloudant to your BlueMix
BlueMix will configure your Cloudant service. Once it is done click the Launch icon to open the Cloudant console.
Refer to the BlueMix docs for more details or troubleshooting.
Now that the Cloudant service is added, it needs to be configured for our use case.
- Create a DB
- Add a read only user
- Put our first news item in the database.
Create a Cloudant Database
Click on the upper right hand corner link that says create database. I named mine blog_news.
Add a read only user
To access this from our the web browser I want to create a read only user ID.
To make and configure the user:
- Select permissions from the left nav
- Click Generate API key
- Validate the new API key only has reader permissions.
When done your screen should look something like this
Store the password for this user somewhere - you can’t retrieve it later.
Create a test news item
To create a test news item:
- Navigate back to the All Documents section on the left Nav
- Click the plus sign next to all documents
- Select New Doc
Your screen should look like this right before you click ‘New Doc’
This should open the Cloudant online JSON text editor. Let’s author our first news item document. Add the following fields for all news article documents. In addition to the _id field inserted automatically by Cloudant we will
Your screen should look something like this.
Record the automatic document id assigned by Cloudant we will need that in the next section.
Click the create document button to insert the document into Cloudant.
To test our process we will retrieve the document we just inserted into Cloudant.
- Get the URL for the document
- Craft a curl to retrieve the document
- Validate document exists and matches what we submitted.
Get the URL for the document
In the all documents view, click on the pencil icon next to the document whose ID matches the document ID you noticed in the previous section. This should bring up an editable version of the document you crafted earlier. In the upper right hand side of the browser click the API icon and then select copy URL.
Your screen should look like this
Create a curl like the one below replacing
Craft your curl
This is what it looks like with some fake values in place.
The results of the curl, should be the same JSON document you just finished creating with a revision id automatically inserted by Cloudant.