(*Handleunknown/unsupportedmethods*)handleMethod[$Failed][request_]:=HTTPResponse["<h1>501 Not Implemented</h1>","StatusCode"501,"Server""ToyServer (wolfram)","Content-Type""text/html"];(*HandletheGETmethod*)handleMethod["GET"][request_]:=Module[{pathString,fileName,statusCode,body,contentType},(*Replace"/"withindex.htmlbyconvention*)pathString=Replace[request["PathString"],"/""index.html"];(*Onlysearchfilesinthesamedirectoryasthescript*)fileName=FileNameJoin[{".",pathString}];(*Ifthefileexists,weimportitscontentsandsentitbackasaresponse(withtheapropriateheaders)*)If[FileExistsQ[fileName],statusCode=200;(*GuesstheMIMEtypeofthefile,defaultto"text/html"*)contentType=First[Import[fileName,"MIMEType"],"TEXT/HTML"];(*Readthecontentsofthefileasabytearray*)body=ReadByteArray[fileName];,statusCode=404;contentType="TEXT/HTML";body="<h1>404 Not Found</h1>";];HTTPResponse[body,"StatusCode"statusCode,"Server""ToyServer (wolfram)","Content-Type"contentType]];