Skip to content

💎 A simple microservice explanation with starter code.

Notifications You must be signed in to change notification settings

reidcampolong/Microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to Build a Simple Microservice

What is a Microservice?

The formal definition can be found here

In simplest terms, imagine breaking down a large application into a bunch of smaller applications, each of which have a specific task.

  • For example, I may build a microservice just to deal with authentication tokens and verifying them

Microservices generally communicate based on HTTP requests.
There can be a lot of benefits to using microservices, but I'll save that for a later discussion. For now, let's get into how to quickly build one!

Technical Information

Built using Maven and Java 8.
Built using Java Spark framework found here

Let's Go!

To launch the application, run the Application.java class.

  • A server is now started on localhost:4567.
  • As defined in our WebServer.java class, we have a /request route that we can send information to.

For this example, we will be using Postman to send HTTP requests to our microservice.

Let's start by entering that URL we have above. In this case, it would be localhost:4567/request Postman image

Great. Now that we are sending a request to the /request route on our microservice, let's add in some query parameters.

  • As defined in our RequestRoute.java, we will be using the 'inputField' parameter in this example Postman image

Awesome. Now we are ready to send the data! Hit send and checkout the response!

  • The response we received is the inputField backwards. In RequestRoute.java, we pass the information into MyController and then return to the user their input backwards. Postman image

What's the Point of This?

Yeah, reversing a string might not be your end goal. Luckily, microservices can be nearly anything you want. For example, try making an authentication server which takes in requests and returns a 'token' assigned to that user.

About

💎 A simple microservice explanation with starter code.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages