Input Form Example
First, take a look at the UI form I created for this exercise. The goal is to add click handler to the submit button, and the save a new document to Carbon based on the form's values.
Input Form HTML
Nothing too fancy - just a simple form using Twitter Bootstrap.
I've included the following scripts on the page...
- moment.js - for generating a publish date in the ISO format I want.
- shim.min.js - from core-js, which is a required polyfill for IE.
And here's the entire working script I've placed below the form on the page to save the input to Carbon.
This script does the following, in general:
- Creates a new platform context (referencing my localhost dev instance of Carbon).
- Defines a function to execute and attaches it to the submit button.
- Within the function, we login to Carbon,
- We get a handle on the particular Carbon application to save data to (test-app/),
- We populate a simple JSON object with the values given by the form,
- And then finally, we persist the JSON document in the root of the application using
return myAppContext.documents.createChild( "/", content, contentSlug );
Viewing Documents in the Workbench
After submitting the form several times to create test documents, I am then able to check for the documents using the Carbon Workbench as shown below...
GET a Document by URI
I can also use my web browser or a REST client to get at any of the individual documents by URI. Following is an example of one of the documents, which I requested to be returned in JSON-LD.
Notice that Carbon automatically generated a vocabulary for the attributes of the JSON object I gave it. For example, for the
title, Carbon created the property URI,
http://localhost:8083/apps/test-app/vocabulary/#title. Carbon provides a means to use existing vocabularies and to create specific vocabulary URIs of own, but as you can see, you don't have to.
- No labels