[JAVA] Introducing Sinatra-style frameworks and how to use them

policy

Don't do complicated things. For individual developers. I'll make a rough article.

Micro framework

Small framework (as is) The point is that you can launch a Web service with the micro framework alone.

How to use

It is a personal usage. Web-like parts are obediently thrown to Nginx, Apache, PHP. Create a Web API for the local network with a micro framework and use Nginx or Apache as the front end.

Introduction of microframes in each language

Sinatra(Ruby) http://www.sinatrarb.com/intro-ja.html Installation is

command


gem install sinatra

The smallest code is

main.rb


require 'sinatra'

get '/' do
  'Hello world!'
end

Public

command


ruby main.rb -p port number-o 0.0.0.0

Spark(Java) http://sparkjava.com/ Installation is

Just DL and pass the path. With Gradle

script


Gradle : compile "com.sparkjava:spark-core:2.5.4" //add to build.gradle

The smallest code is

main.java


import static spark.Spark.*;

public class HelloWorld {
    public static void main(String[] args) {
        get("/hello", (req, res) -> "Hello World");
    }
}

Please compile the publication and execute the jart ball.

Bottle(Python) http://bottlepy.org/docs/dev/ It's light to install, so you can just download it, or use Package Manager or easy_install. If you use pip

command


sudo pip install bottle  

The smallest code is

main.py


from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

Public

command


python main.py

is.

The finished product

Regular expression Tenkomori web service that can be used in Japanese A web service that can also be used for machine learning A web service that can be ported anywhere and do some work Placing the Web API on the local network is also better for security.

Where did you enjoy yourself?

You don't have to study tomcat, Rails, or Django (this is an exaggeration). Easy to distribute, install and test. If you use the server application as API, you can link in each language. You can separate the front end and the server side.

Recommended Posts

Introducing Sinatra-style frameworks and how to use them
Beginners! Basic Linux commands and how to use them!
How to install and use Tesseract-OCR
How to use .bash_profile and .bashrc
How to install and use Graphviz
How to install and use pandas_datareader [Python]
python: How to use locals () and globals ()
How to use Python zip and enumerate
How to use is and == in Python
How to use pandas Timestamp and date_range
How to use xml.etree.ElementTree
How to use Python-shell
How to use lists, tuples, dictionaries, and sets
How to use tf.data
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
[Python] How to use hash function and tuple.
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to install Cascade detector and how to use it
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
[Python] [Django] How to use ChoiceField and how to add options
How to use the grep command and frequent samples
Julia Quick Note [01] How to use variables and constants
How to use argparse and the difference between optparse
How to use Decorator in Django and how to make it
How to use Qt Designer
How to use search sorted
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use IPython Notebook