{"id":13806226,"url":"https://github.com/valvalio/valval","last_synced_at":"2025-05-13T21:32:44.468Z","repository":{"id":65826743,"uuid":"226818047","full_name":"valvalio/valval","owner":"valvalio","description":"The fastest web framework in V language (vlang)","archived":false,"fork":false,"pushed_at":"2020-12-15T17:55:52.000Z","size":73,"stargazers_count":149,"open_issues_count":3,"forks_count":13,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-06-12T22:29:50.219Z","etag":null,"topics":["framework","http","v","v-language","valval","vlang","vweb","web","web-framework"],"latest_commit_sha":null,"homepage":"","language":"V","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/valvalio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-09T08:09:07.000Z","updated_at":"2024-06-10T11:49:07.000Z","dependencies_parsed_at":"2023-02-12T17:25:11.171Z","dependency_job_id":null,"html_url":"https://github.com/valvalio/valval","commit_stats":null,"previous_names":["taojy123/valval"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valvalio%2Fvalval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valvalio%2Fvalval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valvalio%2Fvalval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valvalio%2Fvalval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valvalio","download_url":"https://codeload.github.com/valvalio/valval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213078670,"owners_count":15534443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","http","v","v-language","valval","vlang","vweb","web","web-framework"],"created_at":"2024-08-04T01:01:09.144Z","updated_at":"2024-08-04T01:05:54.485Z","avatar_url":"https://github.com/valvalio.png","language":"V","readme":"# Valval\n\nValval is the fastest web framework in V language. \n\nThis means you can __develop__ a website ___quickly___ and __run__ it ___even faster___!\n\n##### A simple demo:\n\n```v\nimport valval\n\nfn hello(req valval.Request) valval.Response {\n\treturn valval.response_ok('hello world')\n}\n\nfn main() {\n\tmut app := valval.new_app(true)\n\tapp.route('/', hello)\n\tvalval.runserver(app, 8012)\n}\n```\n\n\n## Installation\n\n### Using Git\n```\n$ git clone https://github.com/taojy123/valval\n$ mkdir -p ~/.vmodules\n$ ln -s $(pwd)/valval ~/.vmodules/valval \n```\n\n### Using VPM\nWatchmen123456 has registered the module with vpm. \nSimply use the following if you have v on your PATH variable:\n``` bash\n$ v install watchmen123456.valval\n```\n\n***Note***: If you use vpm; you'll have to change the import to:\n```\nimport watchmen123456.valval\n```\n\n## Quickstart\n\n### A Minimal Application\n\nA minimal Valval application looks something like this:\n```v\n// demo.v\n\nmodule main\n\nimport valval\n\nfn hello(req valval.Request) valval.Response {\n\treturn valval.response_ok('hello world')\n}\n\nfn main() {\n\tmut app := valval.new_app(true)\n\tapp.route('/', hello)\n\tvalval.runserver(app, 8012)\n}\n```\n\nRun server\n```\n$ v run demo.v\n```\n\nThen you can visit `http://127.0.0.1:8012/` to see the website\n```\n$ curl http://127.0.0.1:8012/\nhello world\n```\n\n### Debug Mode\n\nYou can decide whether to use debug mode when calling `valval.new_app()`\n```v\nmut app := valval.new_app(true)  // debug mode\nmut app := valval.new_app(false) // production mode\n```\ndebug mode will print out more infomation while app running\n\n### Service Port\n\nYou can decide the service port number when calling the `valval.runserver()`\n```v\nvalval.runserver(app, 8012)  // listening 8012 port\nvalval.runserver(app, 80)    // listening 80 port\n```\nThe valval server will bind `0.0.0.0` address, so you can visit the website by `127.0.0.1:Port` or `ServerIp:Port`\n\n### Routing\n\nUse the `App.route()` function to band a handler function to request path\n\nThe handler function should have a parameter of type `Request` and return a `Response`\n\n```v\nmut app := valval.new_app(true)\n\napp.route('/', hello)   \t\t         // http://127.0.0.1\n\napp.route('/users', function1)        // http://127.0.0.1/users\napp.route('/user/info', function2)    // http://127.0.0.1/user/info\n\napp.route('POST:/book', function3)  // http://127.0.0.1/book by POST\napp.route('DELETE:/book', function4)    // http://127.0.0.1/book by DELETE\napp.route('/book', function5)         // http://127.0.0.1/book by other methods\n\napp.route('*', function6)   \t\t     // all remain\n\nvalval.runserver(app, 80)\n```\n\n### Accessing Request Data\n\nCurrently, only the following data can be parsed:\n\n- query parameters by GET request; by `valval.Request.query[xxx]`\n- `x-www-form-urlencoded` parameters by POST / PUT / PATCH request; by `valval.Request.form[xxx]`\n\n```v\nfn hello(req valval.Request) valval.Response {\n\tmut name = request.query['name']\n\tif name == '' {\n\t\tname = 'world'\n\t}\n\treturn valval.response_ok('hello $name')\n}\n\nfn post_hello(req valval.Request) valval.Response {\n\tmut name = request.form['name']\n\tif name == '' {\n\t\tname = 'world'\n\t}\n\treturn valval.response_ok('hello $name')\n}\n\napp.route('GET:/hello', hello)\napp.route('POST:/hello', post_hello)\n```\n\n`valval.Request.get()` provides a quick way to get data whether it is from `query` or `form`. \n\n```v\nfn hello(req valval.Request) valval.Response {\n\tname = request.get('name', 'world')  // default: 'world'\n\treturn valval.response_ok('hello $name')\n}\n\napp.route('/hello', hello)\n```\n\nMore types of request data will be supported in the future:\n- parameters in url\n- `multipart/form-data` by POST request\n- `application/json` by POST request\n- uploaded files\n\n### Static Files\n\nUse `valval.App.serve_static` to serve local files\n\n```v\nmut app := valval.new_app(true)\n\napp.serve_static('/static/', './relative/path/to/static/')  \n// visit http://127.0.0.1/static/xxx.js ...\n\napp.serve_static('/static2/', '/absolute/path/to/static2/') \n// visit http://127.0.0.1/static2/yyy.css ...\n\nvalval.runserver(app, 80)\n```\n\n### Rendering Templates\n\nValval used a whole new idea to implement the template function; inspired by [Vue's](https://github.com/vuejs/vue) system.\n\nHas the following advantages:\n\n- You don't need to spend time learning how to use templates, if you have used `Vue` before.\n- If you haven't used `Vue`, you also can [learn](https://vuejs.org/v2/guide/syntax.html) it fast, because it's so easy.\n- It can integrate some commonly used UI frameworks, such as: `element`, `mint`, `vant`, `antd`, `bootstrap`...\n- I don't need to spend time developing built-in templates 😁.\n\nAn example for template:\n\n`server.v`:\n\n```v\nimport valval\nimport json\n\nstruct User {\n\tname string\n\tage int\n\tsex bool\n}\n\nfn users(req valval.Request) valval.Response {\n\n\t// create a view by template file (`test6.html` can be a relative or absolute path)\n\t// use `element` (https://github.com/ElemeFE/element) as ui framework\n\tmut view := valval.new_view(req, 'users.html', 'element') or {\n\t\treturn valval.response_bad(err)\n\t}\n\n\tusers := [\n\t\tUser{'Lucy', 13, false},\n\t\tUser{'Lily', 13, false},\n\t\tUser{'Jim', 12, true},\n\t]\n\tmsg := 'This is a page of three user'\n\n\t// use view.set to bind data for rendering template\n\t// the second parameter must be a json string\n\tview.set('users', json.encode(users))\n\tview.set('msg', json.encode(msg))\n\n\treturn valval.response_view(view)\n}\n```\n\n`users.html`:\n\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eUsers Page\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003c!-- Content in body can use template syntax --\u003e\n        \u003ch3\u003e{{msg}}\u003c/h3\u003e\n        \u003cp v-for=\"u in users\"\u003e\n            \u003cspan\u003e{{u.name}}\u003c/span\u003e ,\n            \u003cspan\u003e{{u.age}}\u003c/span\u003e ,\n            \u003cel-tag v-if=\"u.sex\"\u003eMale\u003c/el-tag\u003e\n            \u003cel-tag v-else\u003eFemale\u003c/el-tag\u003e\n        \u003c/p\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Redirects\n\nUse `valval.response_redirect()` to generate a redirect response\n\n```v\nfn test1(req valval.Request) valval.Response {\n\tname = req.get('name', '')\n\tif name == '' {\n\t\treturn valval.response_redirect('/not_found')\n\t}\n\treturn valval.response_ok('hello $name')\n}\n```\n\n### Responses\n\nIn addition to the responses mentioned above (`response_ok`,  `response_view`, `response_redirect`)\n\nValval also provides other response types, as follows:\n\n```v\nstruct User {\n\tname string\n\tage int\n\tsex bool\n}\n\nfn text(req valval.Request) valval.Response {\n\treturn valval.response_text('this is plain text response')\n}\n\nfn json(req valval.Request) valval.Response {\n\tuser = User{'Tom', 12, true}\n\treturn valval.response_json(user)\n\t// -\u003e {\"name\": \"Tom\", \"age\": 12, \"sex\": true}\n}\n\nfn json_str(req valval.Request) valval.Response {\n\tuser = User{'Tom', 12, true}\n\tuser_str = json.encode(user)\n\treturn valval.response_json_str(user_str)\n\t// -\u003e {\"name\": \"Tom\", \"age\": 12, \"sex\": true}\n}\n\nfn file(req valval.Request) valval.Response {\n\treturn valval.response_file('path/to/local/file')\n}\n\nfn bad(req valval.Request) valval.Response {\n\treturn valval.response_bad('Parameter error!')\n\t// response with statu code 400\n}\n\n```\n\n\n\n## Complete Example\n\n- You can visit https://github.com/taojy123/valval/tree/master/example to see the complete example.\n- And the official website of valval (https://valval.cool) is also written with the valval framework: https://github.com/taojy123/valval_website\n\n\n\n## Install V Language\n\nValval framework currently supports the `V language` version is `0.1.24`\n\nHere are some ways to install V:\n\n### 1. Download a prebuilt V package\n\nVisit official home page https://vlang.io/ to download\n\n\n### 2. Run V in docker [recommand]\n\n```\ndocker run -it -p 8012:8012 --name vlang taojy123/vlang bash\n```\nIt includes OpenSSL\n\n### 3. Install V from source\n```\n$ git clone https://github.com/vlang/v\n$ cd v\n$ make\n```\n\nInstall OpenSSL\n```\nmacOS:\n$ brew install openssl\n\nDebian/Ubuntu:\n$ sudo apt install libssl-dev openssl ca-certificates\n```\nWindows (Win10 Verified):\nSource can be downloaded from: \n* https://www.openssl.org/source/\n* https://github.com/openssl/\n\nYou can find a [Graphic installer](https://slproweb.com/products/Win32OpenSSL.html \"32 and 64 bit available\") if that's more to you're liking.\n\n\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Web"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalvalio%2Fvalval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalvalio%2Fvalval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalvalio%2Fvalval/lists"}