[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4126":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":27,"discoverSource":28},4126,"spark","perwendel\u002Fspark","perwendel","A simple expressive web framework for java. Spark has a kotlin DSL https:\u002F\u002Fgithub.com\u002Fperwendel\u002Fspark-kotlin","",null,"Java",9658,1567,392,204,0,2,65.79,"Apache License 2.0",false,"master",true,[],"2026-06-12 04:00:21","[![](https:\u002F\u002Fimg.shields.io\u002Ftravis\u002Fperwendel\u002Fspark.svg)](https:\u002F\u002Ftravis-ci.org\u002Fperwendel\u002Fspark)\n[![](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fperwendel\u002Fspark.svg)](.\u002FLICENSE)\n[![](https:\u002F\u002Fimg.shields.io\u002Fmaven-central\u002Fv\u002Fcom.sparkjava\u002Fspark-core.svg)](http:\u002F\u002Fmvnrepository.com\u002Fartifact\u002Fcom.sparkjava\u002Fspark-core)\n\nSpark - a tiny web framework for Java 8\n==============================================\n\n**Spark 2.9.4 is out!!**\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.sparkjava\u003C\u002FgroupId>\n    \u003CartifactId>spark-core\u003C\u002FartifactId>\n    \u003Cversion>2.9.4\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\nSponsor the project here https:\u002F\u002Fgithub.com\u002Fsponsors\u002Fperwendel\n\nFor documentation please go to: http:\u002F\u002Fsparkjava.com\u002Fdocumentation\n\nFor usage questions, please use [stack overflow with the “spark-java” tag](http:\u002F\u002Fstackoverflow.com\u002Fquestions\u002Ftagged\u002Fspark-java) \n\nJavadoc: http:\u002F\u002Fjavadoc.io\u002Fdoc\u002Fcom.sparkjava\u002Fspark-core\n\nWhen committing to the project please use Spark format configured in https:\u002F\u002Fgithub.com\u002Fperwendel\u002Fspark\u002Fblob\u002Fmaster\u002Fconfig\u002Fspark_formatter_intellij.xml\n\nGetting started\n---------------\n\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.sparkjava\u003C\u002FgroupId>\n    \u003CartifactId>spark-core\u003C\u002FartifactId>\n    \u003Cversion>2.9.4\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\n```java\nimport static spark.Spark.*;\n\npublic class HelloWorld {\n    public static void main(String[] arg){\n        get(\"\u002Fhello\", (request, response) -> \"Hello World!\");\n    }\n}\n```\n\nView at: http:\u002F\u002Flocalhost:4567\u002Fhello\n\n\nCheck out and try the examples in the source code.\nYou can also check out the javadoc. After getting the source from\n[github](https:\u002F\u002Fgithub.com\u002Fperwendel\u002Fspark) run: \n\n    mvn javadoc:javadoc\n\nThe result is put in \u002Ftarget\u002Fsite\u002Fapidocs\n\nExamples\n---------\n\nSimple example showing some basic functionality\n\n```java\nimport static spark.Spark.*;\n\n\u002F**\n * A simple example just showing some basic functionality\n *\u002F\npublic class SimpleExample {\n\n    public static void main(String[] args) {\n\n        \u002F\u002F  port(5678); \u003C- Uncomment this if you want spark to listen to port 5678 instead of the default 4567\n\n        get(\"\u002Fhello\", (request, response) -> \"Hello World!\");\n\n        post(\"\u002Fhello\", (request, response) ->\n            \"Hello World: \" + request.body()\n        );\n\n        get(\"\u002Fprivate\", (request, response) -> {\n            response.status(401);\n            return \"Go Away!!!\";\n        });\n\n        get(\"\u002Fusers\u002F:name\", (request, response) -> \"Selected user: \" + request.params(\":name\"));\n\n        get(\"\u002Fnews\u002F:section\", (request, response) -> {\n            response.type(\"text\u002Fxml\");\n            return \"\u003C?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\u003Cnews>\" + request.params(\"section\") + \"\u003C\u002Fnews>\";\n        });\n\n        get(\"\u002Fprotected\", (request, response) -> {\n            halt(403, \"I don't think so!!!\");\n            return null;\n        });\n\n        get(\"\u002Fredirect\", (request, response) -> {\n            response.redirect(\"\u002Fnews\u002Fworld\");\n            return null;\n        });\n\n        get(\"\u002F\", (request, response) -> \"root\");\n    }\n}\n\n```\n\n-------------------------------\n\nA simple CRUD example showing how to create, get, update and delete book resources\n\n```java\nimport static spark.Spark.*;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Random;\n\n\u002F**\n * A simple CRUD example showing how to create, get, update and delete book resources.\n *\u002F\npublic class Books {\n\n    \u002F**\n     * Map holding the books\n     *\u002F\n    private static Map\u003CString, Book> books = new HashMap\u003CString, Book>();\n\n    public static void main(String[] args) {\n        final Random random = new Random();\n\n        \u002F\u002F Creates a new book resource, will return the ID to the created resource\n        \u002F\u002F author and title are sent in the post body as x-www-urlencoded values e.g. author=Foo&title=Bar\n        \u002F\u002F you get them by using request.queryParams(\"valuename\")\n        post(\"\u002Fbooks\", (request, response) -> {\n            String author = request.queryParams(\"author\");\n            String title = request.queryParams(\"title\");\n            Book book = new Book(author, title);\n\n            int id = random.nextInt(Integer.MAX_VALUE);\n            books.put(String.valueOf(id), book);\n\n            response.status(201); \u002F\u002F 201 Created\n            return id;\n        });\n\n        \u002F\u002F Gets the book resource for the provided id\n        get(\"\u002Fbooks\u002F:id\", (request, response) -> {\n            Book book = books.get(request.params(\":id\"));\n            if (book != null) {\n                return \"Title: \" + book.getTitle() + \", Author: \" + book.getAuthor();\n            } else {\n                response.status(404); \u002F\u002F 404 Not found\n                return \"Book not found\";\n            }\n        });\n\n        \u002F\u002F Updates the book resource for the provided id with new information\n        \u002F\u002F author and title are sent in the request body as x-www-urlencoded values e.g. author=Foo&title=Bar\n        \u002F\u002F you get them by using request.queryParams(\"valuename\")\n        put(\"\u002Fbooks\u002F:id\", (request, response) -> {\n            String id = request.params(\":id\");\n            Book book = books.get(id);\n            if (book != null) {\n                String newAuthor = request.queryParams(\"author\");\n                String newTitle = request.queryParams(\"title\");\n                if (newAuthor != null) {\n                    book.setAuthor(newAuthor);\n                }\n                if (newTitle != null) {\n                    book.setTitle(newTitle);\n                }\n                return \"Book with id '\" + id + \"' updated\";\n            } else {\n                response.status(404); \u002F\u002F 404 Not found\n                return \"Book not found\";\n            }\n        });\n\n        \u002F\u002F Deletes the book resource for the provided id\n        delete(\"\u002Fbooks\u002F:id\", (request, response) -> {\n            String id = request.params(\":id\");\n            Book book = books.remove(id);\n            if (book != null) {\n                return \"Book with id '\" + id + \"' deleted\";\n            } else {\n                response.status(404); \u002F\u002F 404 Not found\n                return \"Book not found\";\n            }\n        });\n\n        \u002F\u002F Gets all available book resources (ids)\n        get(\"\u002Fbooks\", (request, response) -> {\n            String ids = \"\";\n            for (String id : books.keySet()) {\n                ids += id + \" \";\n            }\n            return ids;\n        });\n    }\n\n    public static class Book {\n\n        public String author, title;\n\n        public Book(String author, String title) {\n            this.author = author;\n            this.title = title;\n        }\n\n        public String getAuthor() {\n            return author;\n        }\n\n        public void setAuthor(String author) {\n            this.author = author;\n        }\n\n        public String getTitle() {\n            return title;\n        }\n\n        public void setTitle(String title) {\n            this.title = title;\n        }\n    }\n}\n```\n\n---------------------------------\n\nExample showing a very simple (and stupid) authentication filter that is executed before all other resources\n\n```java\nimport static spark.Spark.*;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\n\u002F**\n * Example showing a very simple (and stupid) authentication filter that is\n * executed before all other resources.\n *\n * When requesting the resource with e.g.\n *     http:\u002F\u002Flocalhost:4567\u002Fhello?user=some&password=guy\n * the filter will stop the execution and the client will get a 401 UNAUTHORIZED with the content 'You are not welcome here'\n *\n * When requesting the resource with e.g.\n *     http:\u002F\u002Flocalhost:4567\u002Fhello?user=foo&password=bar\n * the filter will accept the request and the request will continue to the \u002Fhello route.\n *\n * Note: There is a second \"before filter\" that adds a header to the response\n * Note: There is also an \"after filter\" that adds a header to the response\n *\u002F\npublic class FilterExample {\n\n    private static Map\u003CString, String> usernamePasswords = new HashMap\u003CString, String>();\n\n    public static void main(String[] args) {\n\n        usernamePasswords.put(\"foo\", \"bar\");\n        usernamePasswords.put(\"admin\", \"admin\");\n\n        before((request, response) -> {\n            String user = request.queryParams(\"user\");\n            String password = request.queryParams(\"password\");\n\n            String dbPassword = usernamePasswords.get(user);\n            if (!(password != null && password.equals(dbPassword))) {\n                halt(401, \"You are not welcome here!!!\");\n            }\n        });\n\n        before(\"\u002Fhello\", (request, response) -> response.header(\"Foo\", \"Set by second before filter\"));\n\n        get(\"\u002Fhello\", (request, response) -> \"Hello World!\");\n\n        after(\"\u002Fhello\", (request, response) -> response.header(\"spark\", \"added by after-filter\"));\n\n        afterAfter(\"\u002Fhello\", (request, response) -> response.header(\"finally\", \"executed even if exception is throw\"));\n\n        afterAfter((request, response) -> response.header(\"finally\", \"executed after any route even if exception is throw\"));\n    }\n}\n```\n\n---------------------------------\n\nExample showing how to use attributes\n\n```java\nimport static spark.Spark.after;\nimport static spark.Spark.get;\n\n\u002F**\n * Example showing the use of attributes\n *\u002F\npublic class FilterExampleAttributes {\n\n    public static void main(String[] args) {\n        get(\"\u002Fhi\", (request, response) -> {\n            request.attribute(\"foo\", \"bar\");\n            return null;\n        });\n\n        after(\"\u002Fhi\", (request, response) -> {\n            for (String attr : request.attributes()) {\n                System.out.println(\"attr: \" + attr);\n            }\n        });\n\n        after(\"\u002Fhi\", (request, response) -> {\n            Object foo = request.attribute(\"foo\");\n            response.body(asXml(\"foo\", foo));\n        });\n    }\n\n    private static String asXml(String name, Object value) {\n        return \"\u003C?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\u003C\" + name +\">\" + value + \"\u003C\u002F\"+ name + \">\";\n    }\n}\n```\n\n\n---------------------------------\n\nExample showing how to serve static resources\n\n```java\nimport static spark.Spark.*;\n\npublic class StaticResources {\n\n    public static void main(String[] args) {\n\n        \u002F\u002F Will serve all static file are under \"\u002Fpublic\" in classpath if the route isn't consumed by others routes.\n        \u002F\u002F When using Maven, the \"\u002Fpublic\" folder is assumed to be in \"\u002Fmain\u002Fresources\"\n        staticFileLocation(\"\u002Fpublic\");\n\n        get(\"\u002Fhello\", (request, response) -> \"Hello World!\");\n    }\n}\n```\n---------------------------------\n\nExample showing how to define content depending on accept type\n\n```java\nimport static spark.Spark.*;\n\npublic class JsonAcceptTypeExample {\n\n    public static void main(String args[]) {\n\n        \u002F\u002FRunning curl -i -H \"Accept: application\u002Fjson\" http:\u002F\u002Flocalhost:4567\u002Fhello json message is read.\n        \u002F\u002FRunning curl -i -H \"Accept: text\u002Fhtml\" http:\u002F\u002Flocalhost:4567\u002Fhello HTTP 404 error is thrown.\n        get(\"\u002Fhello\", \"application\u002Fjson\", (request, response) -> \"{\\\"message\\\": \\\"Hello World\\\"}\");\n    }\n} \n```\n---------------------------------\n\nExample showing how to render a view from a template. Note that we are using `ModelAndView` class for setting the object and name\u002Flocation of template. \n\nFirst of all we define a class which handles and renders output depending on template engine used. In this case [FreeMarker](http:\u002F\u002Ffreemarker.incubator.apache.org\u002F).\n\n\n```java\npublic class FreeMarkerTemplateEngine extends TemplateEngine {\n\n    private Configuration configuration;\n\n    protected FreeMarkerTemplateEngine() {\n        this.configuration = createFreemarkerConfiguration();\n    }\n\n    @Override\n    public String render(ModelAndView modelAndView) {\n        try {\n            StringWriter stringWriter = new StringWriter();\n\n            Template template = configuration.getTemplate(modelAndView.getViewName());\n            template.process(modelAndView.getModel(), stringWriter);\n\n            return stringWriter.toString();\n        } catch (IOException e) {\n            throw new IllegalArgumentException(e);\n        } catch (TemplateException e) {\n            throw new IllegalArgumentException(e);\n        }\n    }\n\n    private Configuration createFreemarkerConfiguration() {\n        Configuration retVal = new Configuration();\n        retVal.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, \"freemarker\");\n        return retVal;\n    }\n}\n```\n\nThen we can use it to generate our content. Note how we are setting model data and view name. Because we are using FreeMarker, in this case a `Map` and the name of the template is required:\n\n```java\npublic class FreeMarkerExample {\n\n    public static void main(String args[]) {\n\n        get(\"\u002Fhello\", (request, response) -> {\n            Map\u003CString, Object> attributes = new HashMap\u003C>();\n            attributes.put(\"message\", \"Hello FreeMarker World\");\n\n            \u002F\u002F The hello.ftl file is located in directory:\n            \u002F\u002F src\u002Ftest\u002Fresources\u002Fspark\u002Fexamples\u002Ftemplateview\u002Ffreemarker\n            return modelAndView(attributes, \"hello.ftl\");\n        }, new FreeMarkerTemplateEngine());\n    }\n}\n```\n\n---------------------------------\n\nExample of using Transformer.\n\nFirst of all we define the transformer class, in this case a class which transforms an object to JSON format using gson API.\n\n```java\npublic class JsonTransformer implements ResponseTransformer {\n\n\tprivate Gson gson = new Gson();\n\n\t@Override\n\tpublic String render(Object model) {\n\t\treturn gson.toJson(model);\n\t}\n}\n```\n\nAnd then the code which return a simple POJO to be transformed to JSON:\n\n```java\npublic class TransformerExample {\n\n    public static void main(String args[]) {\n        get(\"\u002Fhello\", \"application\u002Fjson\", (request, response) -> {\n            return new MyMessage(\"Hello World\");\n        }, new JsonTransformer());\n    }\n}\n```\n\nDebugging\n------------------\nSee [Spark-debug-tools](https:\u002F\u002Fgithub.com\u002Fperwendel\u002Fspark-debug-tools) as a separate module.\n","Spark 是一个简洁且富有表现力的 Java Web 框架，也支持 Kotlin 语言。它提供了轻量级的核心功能，如路由、请求处理和响应生成，使开发者能够快速构建 Web 应用程序。Spark 的设计注重简洁性和易用性，通过简单的 API 和链式调用来实现强大的功能。适用于需要快速开发小型到中型规模 Web 应用或微服务的场景，特别是当项目对框架的复杂度有严格限制时。此外，Spark 支持多种中间件集成，方便扩展应用功能。","2026-06-11 02:58:35","top_language"]