useMojolicious::Lite;usev5.20;useexperimental'signatures';get'/'=>'index';under(sub{my$self=shift;unless($self->req->json){$self->render(json=>{status=>"error",data=>{message=>"No JSON found"}});returnundef;}my$username=$self->req->json->{username};my$api_key=$self->req->json->{api_key};unless($username){$self->render(json=>{status=>"error",data=>{message=>"No username found"}});returnundef;}unless($api_key){$self->render(json=>{status=>"error",data=>{message=>"No API Key found"}});returnundef;}unless("fnord"eq$username){$self->render(json=>{status=>"error",data=>{message=>"Credentials mis-match"}});returnundef;}unless("68b329da9893e34099c7d8ad5cb9c940"eq$api_key){$self->render(json=>{status=>"error",data=>{message=>"Credentials mis-match"}});returnundef;}return1;});post'/api/v1/hello'=>sub($c) {return($c->render(json=>{status=>"success"}));};put'/api/v1/hello'=>sub($c) {return($c->render(json=>{status=>"success is a put"}));};get'/api/v1/hello'=>sub($c) {return($c->render(json=>{status=>"we like get"}));};app->start;__DATA__@@index.html.epTry:<br>POST/api/v1/hello
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.