Coder Social home page Coder Social logo

gedframework-official-mirror's Introduction

GedFramework

A light-weight website framework

In developing

Import

maven

<dependency>
    <groupId>net.deechael</groupId>
    <artifactId>ged-framework</artifactId>
    <version>1.03.0</version>
</dependency>

gradle

dependencies { 
    //...
    implementation 'net.deechael:ged-framework:1.03.0'
}

Quick start

package net.deechael.framework.test;

import net.deechael.framework.*;
import net.deechael.framework.content.FileContent;
import net.deechael.framework.content.StringContent;
import net.deechael.framework.item.Item;
import net.deechael.framework.item.ItemArgument;
import net.deechael.framework.item.ItemArgumentType;
import net.deechael.framework.item.ItemConstructor;

@Websites({
        @Website(port = 8080),
        @Website(port = 4430, ssl = true, sslProvider = PemSSLProvider.class)
})
public class ExampleWebsite {

    public static void main(String[] args) throws InterruptedException {
        try {
            GedWebsite website = new GedWebsite(ExampleWebsite.class);
            new JksSSLProvider();
            website.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Item
    public static class User {

        private String userAgent;

        @ItemConstructor
        public User(@ItemArgument(type = ItemArgumentType.HEADER, name = "user-agent") String userAgent) {
            this.userAgent = userAgent;
        }

        public String getUserAgent() {
            return userAgent;
        }

    }

    @Path("/itemtest")
    public static void itemTest(Request request,
                                Responder responder,
                                @Argument(value = "", type = ArgumentType.ITEM) User user) {
        responder.setContent(new StringContent("Welcome!\n" +
                "Your user agent is:\n" +
                user.getUserAgent()));
    }

    @RequestMethod(HttpMethod.GET)
    @Path("/header-testing")
    public static void headerTest(Request request, Responder responder, @Header("User-Agent") String contentType) {
        responder.setContent(new StringContent("Your content type is " + contentType));
    }

    @RequestMethod(HttpMethod.GET)
    @Path("/test")
    public static void test(Request request, Responder responder) {
        responder.setContent(new StringContent("hello, world! your address is " + request.getUserAddress()));
    }

    @RequestMethod(HttpMethod.GET)
    @Paths({
            @Path("regexer"),
            @Path(value = "/?regex/(test|fuck|blabla)", regex = true)
    })
    public static void regexTest(Request request, Responder responder) {
        responder.setContent(new StringContent("Regex test success!"));
    }

    @RequestMethod(HttpMethod.GET)
    @Path(value = "/list", ignoreCaps = true)
    public static void list(Request request, Responder responder,
                            @Argument(value = "username", type = ArgumentType.STRING) String username,
                            @Argument(value = "password", type = ArgumentType.STRING) String password) {
        responder.setContent(new StringContent("hello, world!\nfull url: " + request.getFullUrl() + "\nusername: " + username + "\npassword: " + password));
    }

    @Path("/")
    public static void main(Request request, Responder responder) {
        responder.setContentType(ContentType.TEXT_HTML);
        responder.setContent(new FileContent("index.html"));
    }

    @Path("/js/%s")
    public static void js(Request request, Responder responder) {
        responder.setContentType(ContentType.TEXT_JAVASCRIPT);
        responder.setContent(new FileContent("js/" + request.getPaths()[1]));
    }

    @Path("/css/%s")
    public static void css(Request request, Responder responder) {
        responder.setContentType(ContentType.TEXT_CSS);
        responder.setContent(new FileContent("css/" + request.getPaths()[1]));
    }

    @UnknownPath
    public static void unknown(Request request, Responder responder) {
        responder.setContent(new StringContent("All will redirect to me!"));
    }


}

gedframework-official-mirror's People

Contributors

deechael avatar

Stargazers

 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.