Log in
Sign up
Documentation
  • - Quick start guides
  • - Using Java
  • - Using Node.js
  • - Using Python
  • - Using React
  • - How Jumpydoll works
  • - Tutorials

Quick start guide (Java)

  • Creating your project
  • Making your first change
  • Viewing your change
  • Local setup
  • Next steps

Get started with Spring Boot on Jumpydoll in 5 minutes. This guide will walk you through creating a new project, making your first change, and deploying the change.

Spring Boot is a Java framework that makes it easier to build applications in Java. It is most commonly used to easily build a web backend that can respond to HTTP requests. In this guide, you'll learn how to create a new Spring Boot project, create an API endpoint to respond to a web request, and view your change publicly on Jumpydoll.

This guide is adapted from the "Building a RESTful Web Service" guide from Spring.

Creating your project

Make sure you have a Jumpydoll account and have the Jumpydoll Github app installed on all repositories on your account.

To create your project:

  • Log into Jumpydoll and go to the application create page (https://jumpydoll.com/applications/create).

  • Type in Spring Boot service as the project name

  • Type in A sample Spring Boot web service in the project description and click Next

  • Select the Java/Spring Boot template

  • Click "Create my project"

After creating the app, you will be redirected to the project management page. On this page, you can see the code repository, build status, and application configuration. When you create a project, Jumpydoll creates a new GitHub repository in your account containing the initial Java code. When you make a change to this GitHub repository, your code will automatically build and deploy to our servers. Let's try making a change now.

Making your first change

Before making the first change, let's view the initial version of the application. Click on the "URL" link at the top of the page. Here you can see the home page of the initial template.

For your first change, you'll be making a simple "Hello world" REST API. An API or Application Programming Interface is an interface that is built for applications to programmatically interact with a resource. When you want to perform complex operations (reading/writing data to a database), it's best to build a backend that performs all of these functions. By building an API in your backend, you can simplify the development of the user interface or frontend. Your frontend can make calls to the backend to do the real work, and the frontend remains simple because it uses the API, which is designed for code to call it. REST APIs are one design pattern for web APIs, where requests are sent to specific URLs to perform actions.

You can start your first change right in the browser. Navigate to the manage page of your app. From here, you can click on the "Code" button, and click on "Code in the browser" to start writing code using GitHub's browser editor.

First, you need to create an object to represent data consistently. Create a new file called Greeting.java in the src/main/java/com/jumpydoll/app/[user]/springbootservice folder. This class should have two fields: id, and content. It should also have a constructor and getters for those fields. Your file should look like this:

src/main/java/com/jumpydoll/app/[user]/springbotservice/Greeting.java

package com.jumpydoll.app.[user].springbootservice;

public class Greeting {

	private final long id;
	private final String content;

	public Greeting(long id, String content) {
		this.id = id;
		this.content = content;
	}

	public long getId() {
		return id;
	}

	public String getContent() {
		return content;
	}
}

This class is a simple Java class for an object that stores data for use in your Java code. It's not tied to any database or external service. Since it's just a simple Java object, it's often referred to as a "Plain Old Java Object" or POJO. Spring can convert this object to JSON, a commonly used data format that is easy to parse with code consistently.

Next, you'll create a REST controller. Spring Boot uses a component called a REST controller to define REST APIs. You can create a Java method that performs certain actions and then define what URL should be called to run that code. Create a new file in the src/main/java/com/jumpydoll/app/[user]/springbootservice directory called GreetingController.java. Paste the code below in the file.

src/main/java/com/jumpydoll/app/[user]/springbotservice/GreetingController.java

package com.jumpydoll.app.[user].springbootservice;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

	private static final String template = "Hello, %s!";
	private final AtomicLong counter = new AtomicLong();

	@GetMapping("/greeting")
	public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
		return new Greeting(counter.incrementAndGet(), String.format(template, name));
	}
}

If you don't understand this file, don't worry too much about it. The Java annotations (lines starting with @) tell Spring about this class and Spring handles all of the heavy-lifting in the background. What you should know is that you annotate the class with @RestController to tell Spring that this class should be used as a controller to define the REST API. To add new URLs to the API, you can add a mapping (in this case a GetMapping since you're getting data) to a method, which tells Spring to call that method when it receives a request to the corresponding URL. The RequestParam annotation tells Spring to fill the name parameter with a value in the request. Lastly, Spring will convert your return value into JSON to return to the requester.

This is all you need to create your first API. To push the changes, go to the "Version control" tab on the sidebar. Click the plus icons next to the Greeting.java and GreetingController.java files so they are committed in the next version. Add a commit message of "Add a hello world API" and press the checkmark to commit. This creates a new commit which is automatically pushed to GitHub to start building.

Viewing your change

Back on the manage page of your app, you should see your new change start building. Once the build has finished, refresh and you should see the config version update in the "Deployment" section. Click the "Visit App" button to see your changes. The main page will stay the same, but if you navigate to https://[user].app.jumpydoll.com/spring-boot-service/greeting, you will see your new API.

Replace /greeting with /greeting?name=User and you will see the response change. This is one way to pass a dynamic argument into the API.

Local setup

This guide uses the GitHub browser IDE to help you get started without any local setup. As you develop more complex applications, you'll want to be able to use your choice of IDE and test your code locally. To start developing locally, you'll need an IDE and git.

Eclipse and IntelliJ are the two most popular Java IDEs. Check out these links to download them:

You will use git to pull your code and push any changes you make. Git is an open-source version control system. It helps you track different versions of your work and makes it easy for multiple collaborators to merge their work. Many IDEs (including Eclipse and IntelliJ) have Git support built-in, so you don't need to install anything extra. Follow your IDE's instructions for cloning a repository and creating/pushing commits. You can also install Git to your terminal or use GitHub Desktop if you prefer a standalone solution.

Next steps

Try Jumpydoll and host your own project

• Sign up with a GitHub account
• No setup required - start right in your browser
• Start your first project in 5 minutes
Get started for free

Jumpydoll

About

Project Gallery

Sign up

Contact

Email: brian@jumpydoll.com

© 2022