Skip to content

vlib: vanilla_http_server #24202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

enghitalo
Copy link
Contributor

@enghitalo enghitalo commented Apr 12, 2025

module main

import enghitalo.vanilla.http_server
import enghitalo.vanilla.request_parser

fn handle_request(req_buffer []u8, client_conn_fd int) ![]u8 {
	req := request_parser.decode_http_request(req_buffer)!
	method := request_parser.slice_to_string(req.buffer, req.method)
	path := request_parser.slice_to_string(req.buffer, req.path)

	match method {
		'GET' {
			match path {
				'/' {
					return home_controller([])
				}
				'/users' {
					return get_users_controller([])
				}
				else {
					if path.starts_with('/user/') {
						id := path[6..]
						return get_user_controller([id])
					}
					return http_server.tiny_bad_request_response
				}
			}
		}
		'POST' {
			if path == '/user' {
				return create_user_controller([])
			}
			return http_server.tiny_bad_request_response
		}
		else {
			return http_server.tiny_bad_request_response
		}
	}

	return http_server.tiny_bad_request_response
}

fn main() {
	mut server := http_server.Server{
		port:            3000
		request_handler: handle_request
	}
	server.run()
}

@Avey777
Copy link

Avey777 commented Apr 26, 2025

This is not merged, is there any problem?

@spytheman
Copy link
Member

This is not merged, is there any problem?

Initially it had failing CI jobs.

After reviewing it, I think that it should stay in its own repository - https://github.com/enghitalo/vanilla_http_server . The instructions in the PR are already written with that repository in mind.

@spytheman spytheman closed this Apr 28, 2025
@medvednikov
Copy link
Member

We've had some issues with picoev + veb lately. I think this is a great alternative in pure V + it supports multithreading. I think it should not only be included into the examples directory, but it should become the web server Veb uses.

@spytheman
Copy link
Member

I think, that we already do have several platform independent web servers in vlib - vweb, veb, which currently use picoev as infrastructure, and the pure V one in vlib/net/http/server.v, available through v -http.

I think, that this new one, should not be in vlib, even if it is good as a standalone project.

However, if you do want to merge it in vlib/, @medvednikov, then go ahead, or at least provide the instructions needed for integration, instead of letting it sit here in limbo.

@enghitalo enghitalo marked this pull request as draft May 22, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants