Quick actions

cmd+k|ctrl+k

Navigation

Languages

http

Snippet info

Language

Elixir

Visibility

public

Author

jsonkody

Created

2025-10-29T10:41:54.941229Z

Updated

2025-10-29T12:04:20.196572Z

defmodule Http do

# request = """
# GET /wildthings HTTP/1.1
# Host: example.com
# User-Agent: fisdfodjfoidsjfoij
# Accept: */*

# """

def handle(request) do
    request
    |> parse
    |> route
    |> log
    |> format_response
    |> log_h
end

def parse(request) do
    [method, path, _] = request 
    |> String.split("\n") 
    |> List.first
    |> String.split(" ")
    
    # conv = %{ method: "GET", path: "/wildthings", resp_body: "" }
    %{ method: method, path: path, resp_body: "" }
end

def log(conv), do: IO.inspect conv
def log_h(conv), do: IO.puts conv


def route(conv) do
    %{ conv | resp_body: "Jenda dva a dvacet .. a ahojko dvojko" }
end


def format_response(conv) do
    """
    HTTP/1.1 200 OK
    Content-Type: text/html
    Content-Length: #{String.length(conv.resp_body)}
    
    #{conv.resp_body}
    """
end





end

request = """
GET /wildthings HTTP/1.1
Host: example.com
User-Agent: fisdfodjfoidsjfoij
Accept: */*

"""

Http.handle(request)
INFO