Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Getting started

Dmytro edited this page Jan 29, 2017 · 8 revisions

To start using a framework, you must create a maven-project and paste address of the repository in pom.xml file and fill dependencies section like that:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example.group.id</groupId>
  <version>0.1</version>
  <artifactId>exampleId</artifactId>
  <repositories>
      <repository>
          <id>jitpack.io</id>
          <url>https://jitpack.io</url>
      </repository>
  </repositories>
  <dependencies>
    <dependency>
       <groupId>com.github.ummo93</groupId>
       <artifactId>EasyWeb</artifactId>
       <version>dfe6fc7e8e</version>
   </dependency>
  </dependencies>
</project>

Go to the sources directory to Main.java file and start with:

import com.appartika.easyweb.App;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        App app = new App();
        
        app.get("/", (req, res) -> {
            return res.send("ok", 200);
        });
        
        app.listen(5000);
    }
}

After that, if all is right, you will may open a browser at 'localhost:5000' address, and watch an "ok" message.

A few additional features:

/* Set a path for static files such as .ftl templates, .html, .json, etc... **/
app.setStaticPath("./src/main/resources/");
/* Set a path for public files such as scripts, which downloaded from static pages (.css, .js, etc...) **/
app.setPublicPath("./src/main/resources/public/");

If you want to better distribute the structure of your application, you can write handlers in one place, and handle them in another, for example:

app.get("/", Controller::mainPage);

Where Controller::mainPage is a the same thing as call Controller.mainPage(req, res). Thus you can process requests within the Controller class.

Clone this wiki locally