SparkJava: RESTful APIs
Creating RESTful APIs with SparkJava
When we think of web apps, we normally think of a human end user interacting with the web app through a browser.
- The pages are rendered in HTML/CSS/JavaScript in Chrome, Firefox or Safari
- The user a human on a smart phone or tablet, reading pages, and then clicking, selecting, and/or typing in data
But many web applications either instead of this, or in addition to this, provide RESTful APIS.
RESTful APIs are typically NOT designed for human end users; instead, you can think of them as web apps for other pieces of software.
- The “users” are programs that send web requests, these days, typically formatted in JSON (JavaScript Object Notation)
- The replies are also typically formatted in JSON
(Note that in the past, it was more common for RESTful APIs to use XML instead of JSON, and many still do. However, we’ll focus on JSON in this course.
RESTful APIS provide:
- a way for programs written in any language with libraries for http and json (which is pretty much every language these days) to access data from online sources (e.g. Google Maps, Google Places)
- an alternative way to build a web app for humans, where the “formatting” is done by a client side JavaScript library such as AngularJS or ReactJS(https://reactjs.org).
Here are some examples of building RESTful APIs using SparkJava
- https://github.com/ucsb-cs56-pconrad/sparkjava-lombok-jackson-example
- A very simple example of JUST a RESTful API
- https://github.com/ucsb-cs56-pconrad/sparkjava-rest-mlab-frontend
- This one has a frontend along with a RESTful API
More on SparkJava: RESTful APIs
- SparkJava: Authentication—login/logout, and securing various pages in your app
- SparkJava: Bootstrap—Adding a nicer looking UI, with common navigation, drop down menus, etc.
- SparkJava: Facebook API—Authenticate with Facebook, then access the Facebook API
- SparkJava: Getting Started—A more clear tutorial
- SparkJava: Github API—Authenticate with Github, then access the Github API
- SparkJava: Image Files—and any other static files your application needs
- SparkJava: MongoDB—Using the NoSQL database MongoDB with SparkJava
- SparkJava: pac4j—Securing a SparkJava webapp, with options for OAuth or LDAP
- SparkJava: RESTful APIs—Creating RESTful APIs with SparkJava
- SparkJava: SLF4J—What is the Simple Logging Framework For Java, and how to configure it
- SparkJava: Templates—The various template engines you can use with SparkJava