Git Product home page Git Product logo

jserve's Introduction

JServe

A Java framework for building web applications (using a built-in HTTP 1.1 compliant server).

Goals

The goals are as stated:

  • Providing a framework that serves the general usage of a web server (with good performance in mind).
  • Maintaining a clean/readable codebase.

Tradeoffs: If it comes to it, I'm somewhat of a germaphobe with code, so clean will mostly win over, unless it's an order of magnitude difference in performance, and puts the application at risk.

Important Notes

Relies on Java 8+ API's.

Quick Setup

You can install the jar (from the releases page) or install it from maven/gradle. More information will be available soon on this process.

Examples

Demonstration of GET request handling

import com.devsegal.jserve.HTTPServer;
import com.devsegal.jserve.ResponseHeaders;

HTTPServer server = new HTTPServer(8080);

server.route("/", "GET", (request, response) -> {

  try {
        response.setResponseHeaders(new ResponseHeaders("text/html", "close"));
      } catch(ResponseStatusNullException e) {
        e.printStackTrace();
      } 
      
  response.insertContent("Hello world!");
  response.send();
});

server.run(); 

Demonstration of POST request handling

import com.devsegal.jserve.HTTPServer;
import com.devsegal.jserve.ResponseHeaders;
import java.util.Map;

HTTPServer server = new HTTPServer(8080);
server.setupOriginalServerPath("path/to/server/folder"); // Where files are read from (excluding the public assets folder)

// your login page of choice
server.route("/login", "GET", (request, response) -> {
  
  try {
      response.setResponseHeaders(new ResponseHeaders("text/html", "close"); 
  } catch(ResponseStatusNullException e) {
      e.printStackTrace();
  } 
  
  response.readContentFromFile("login.html");
});

server.route("/login", "POST", (request, response) -> {
  // Assuming we won't send anything back, just send an empty response 
  response.send();
  
  // Now, get all data posted 
  Map<String, String> postData = request.getPostData(); 
  
  // get the username 
  String username = postData.get("username");
  
  // get the password
  String password = postData.get("password");
  
  // save it somewhere
  // ...
});

Changelog

The changelog has been moved to its own file

To-Do List (everything that needs to be done to merit a new release)

  • (done) Introduce middleware at some level. This might be as simple as creating hooks, so middleware "plug-ins" could be activated at certain places in code. Or, they could be more complex creatures with lifecycles and such things as I've imagined... We'll have to see what makes sense.

  • (currently in progress) Make importing the library as easy as using respositories like Maven Central (in gradle/maven). For some reason, this is something that somehow keeps getting me annoyed - after reading many many tutorials. I've determined the best way to proceed is just to accept it, and read directly from Maven's site on the process.

  • (done) Resolve the issue with the public asset folder's structure. What JServe currently does is like flattening a list of lists (basically putting the lists (in the list) elements in the original list, thus "flattening" the list into one list, rather than a list of lists. Now, replace the idea of lists with directories, and a list with a root directory, and suddenly it's very analogous.

  • (done) Unit Testing (integration testing will be a future consideration, but at the very least I'd like to create an extensive suite of unit tests)

This is way too subjective. It was more of a motivational, go-get-started kind of reminder, than a fixed point which I was aiming for (what is extensive? do we measure that by number of unit tests? do we assess each one?)

  • (done) Thorough Javadoc Documentation (extensively, at a minimum covering BaseHTTPServer, and hopefully the rest of the server)

This is also way too subjective. Definitely a way to get started doing it (which did end up happening), so I'll consider it's mission accomplished, and in the future come up with very very specific metrics to easily measure how much progress has been made in each of these tasks.

  • (done!) Serve (by default) binary files instead of ASCII encoded text files - so people can serve images, videos, and other file formats.

The following are tasks that could be done now, but could also be pushed off to later versions depending on the mood.

  1. Support/Compatibility for Android
  2. Add logging instead of intrusive and unwelcomed stdout message clogging

Help Out

Giving a helping hand to an open source project is really easy, however intimidating it might be (which it shouldn't!). There are tons of stuff to be done - namely features, fixes (even identifying bugs and opening issues), and helping sustain the project's goals/vision. You're encouraged to make/suggest changes in the code/documentation, mess around with things, and try stuff out. The main things to be done (as I see them) are listed in the To-Do section. I'm not really tied to the ordering of it, (thus warranting the use of an unordered list), but they're the most direct conflicts between the project's current state, and where I want it to go. Changes that might seem minute (like improving the writing of READMEs or improving a comment - which isn't really minute, but that's tangential...) are very important to the project's health.

jserve's People

Contributors

16bits3g4l avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.