SDK Examples

# Examples ... to show you the way

We believe examples are key to increasing understanding and expertise of our SDKs. This page provides a gateway to all of the browser-side examples, which take you from the simple stuff (listing apps and creating searches) to more complicated use cases (integrating with third-party visualization tools), and finally to MiniSplunk, an example that clones some of Splunk's core features.

A few notes:

- All of the examples (except MiniSplunk) provide you with code snippets and the ability to run that code. They run against your own installation of Splunk (log in at the top of the page). Don't just scan the code, go ahead and run the examples!

- The JavaScript SDK communicates with splunkd, but it's not on the same host as the web server that is serving your page. Due to the browser's Single Origin Policy, we can't communicate with it directly. So, the examples provide all of the parameters to the example web server, which then proxies it to splunkd (that's what those `ProxyHttp` lines are all about).

- We highly recommend you open up the developer console while running the examples to see which requests the SDK is making. It can be quite educational.

### Simple examples ("Hello, world"-style)

These examples are meant to show off single, simple aspects of the SDK. These examples have nearly no configuration, and are mirror images of the respective server-side examples. Here, you'll see how to list applications, list saved searches and their queries, and create various types of searches (including real-time searches) and display the results.

You can run each of these examples in your browser, and you'll see the output in a dedicated output pane. Some examples have multiple versions—for example, some provide code with and without the `splunkjs.Async` library.

### UI examples (with pretty pictures)

Splunk has always had very strong visualization capabilities, both for displaying an overview of your event timeline, as well as charting your queries in meaningful ways. We're excited to be able to give you access to the Splunk Timeline control and the Splunk Charting control, which are the same controls that are included with Splunk 4.3+ (no Flash!). We didn't exclude or limit them in any way, and we hope that you find them useful to better visualize your data.

These examples show how to use the Timeline and Charting controls with the SDK. They run a simple search on Splunk and visualize the data as it becomes available.

Note: While the controls work best with the SDK (because it provides data in the expected formats), the SDK itself is not required. You can use the minimal module (`splunk.ui.{min}.js`), which contains just the asynchronous script loader to bring up the UI controls you want.

### Integration with third-party visualization tools (you might have other friends)

As we said, Splunk has extremely strong visualization tools. However, we simply can't think of (or implement) every type of visualization out there. But now, with the JavaScript SDK, visualizing your Splunk data in new and exciting ways has never been easier.

These examples show how to integrate Splunk search results with a couple of visualization libraries:

- Google Charts—a simple, yet powerful charting library provided by Google.

- Rickshaw—a time-series visualization library, based on the extremely powerful d3 library.

  Note: Due to browser limitations, the Rickshaw example doesn't work in Internet Explorer 9 or earlier.

### MiniSplunk (the whole shebang)

As you can imagine, Splunk Web is the most complex Splunk application and biggest user of the REST API. Given that premise, we thought it was important to show that our JavaScript SDK can build a similar application—and so MiniSplunk was born.

MiniSplunk is the first example we wrote, and also the most complex. It shows how to build a full application using the JavaScript SDK. You can search, manage jobs, and even map your search results (if they include geodata). We will keep updating the example with additional advanced features as time goes on.