Giter VIP home page Giter VIP logo

simple-webserver-and-rest-with-jetty-and-no-xml's Introduction

Simple webserver with WebSocket and REST using jetty and NO XML

This is a very simple RESTful web service implemented using jetty embedded. I wrote this to answer the pressing question: do I need a container a a ton of xml to get anything done with java and the web?

The answer is.... NO.

It actually took three classes, 15 minutes and about 150 lines of code to implement:

  • a very (very) basic in-memory key-value store with a REST API
  • a simple static file server
  • a unique id generator

Benchmarks

I gave the thing 8m memory (-Xmx8m - yes, megabytes) and tried to push it with apache ab:

# 2000 threads doing 50000 put to the store (always same key) 
ab -u data.txt -c 2000 -n 50000 http://localhost:8180/store/somekey

Time taken for tests:   30.371 seconds
Requests per second:    1646.31 [#/sec] (mean)    

WebSocket demo

  • browse to /quotes.html to receive a countinuous supply of quotes from The Hitchhicker Guide To the galaxy

Key-Value store api

  • GET /store/ - the value associated with key or 404
  • PUT /store/ - put the body of the request as value of key
  • DELETE /store/ - deleted the value or 404

File server

  • GET / - will show htdocs/index.html
  • GET /about.html - will show htdocs/about.html
  • and so on

Unique id generator

  • GET /uuid - get a fresh uuid at each hit

compile and run

with maven

mvn assembly:assembly
java -jar target/simple-jetty-rest-1.0-SNAPSHOT-jar-with-dependencies.jar

with eclipse

mvn eclipse:eclipse
in eclipse file->import->existing project...
then run main

Bitdeli Badge

simple-webserver-and-rest-with-jetty-and-no-xml's People

Contributors

caprazzo avatar bitdeli-chef avatar

Watchers

xunian 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.