raku-community-modules / Web-App

Licence: other
A Web Application foundation for Raku

Programming Languages

Raku
181 projects

Projects that are alternatives of or similar to Web-App

UberCarAnimation
This app is for animating a car like uber from one position to another with preserving angle and smooth animation
Stars: ✭ 53 (+152.38%)
Mutual labels:  hacktoberfest2020
spamtoberfest
Fight against PR spammers
Stars: ✭ 51 (+142.86%)
Mutual labels:  hacktoberfest2020
Footnote
Simple SwiftUI + CoreData app
Stars: ✭ 38 (+80.95%)
Mutual labels:  hacktoberfest2020
website-www.codeuino.org
www.codeuino.org/
Stars: ✭ 35 (+66.67%)
Mutual labels:  hacktoberfest2020
workshop-subscription-system
No description or website provided.
Stars: ✭ 28 (+33.33%)
Mutual labels:  hacktoberfest2020
godot tools
A set of GDScript EditorScript and EditorPlugins tools that automate boring tasks on Godot Engine.
Stars: ✭ 50 (+138.1%)
Mutual labels:  hacktoberfest2020
Stanley
An Android app explorer for developers (extract the manifest and other info from any installed application)
Stars: ✭ 82 (+290.48%)
Mutual labels:  hacktoberfest2020
HacktoberFest2021
hacktoberfest-accepted repository
Stars: ✭ 25 (+19.05%)
Mutual labels:  hacktoberfest2020
Recursion-Tree-Visualizer
A simple python package that helps to visualise any recursive function by adding a single line of code.
Stars: ✭ 89 (+323.81%)
Mutual labels:  hacktoberfest2020
styles
A collection of cool effects in html, css and javascript.
Stars: ✭ 35 (+66.67%)
Mutual labels:  hacktoberfest2020
oauth-jsclient
Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
Stars: ✭ 102 (+385.71%)
Mutual labels:  hacktoberfest2020
AzSubscriptionCleaner
Delete automatically the useless resources in your Azure subscription.
Stars: ✭ 29 (+38.1%)
Mutual labels:  hacktoberfest2020
Algoflow
Algorithm Visualizer
Stars: ✭ 21 (+0%)
Mutual labels:  hacktoberfest2020
IssueAi
O Issue Ai cria um espaço de visibilidade para os projetos open source de Computação@UFCG.
Stars: ✭ 32 (+52.38%)
Mutual labels:  hacktoberfest2020
Inheritance-2020
Official Repository for Inheritance Submissions 2020
Stars: ✭ 18 (-14.29%)
Mutual labels:  hacktoberfest2020
tetriss
Tetris clone written in JavaScript 🎮 https://antonioolf.github.io/tetriss/
Stars: ✭ 14 (-33.33%)
Mutual labels:  hacktoberfest2020
CBJ Smart-Device Resources
🧰 Have you ever wondered if there is an open-source project to make your own smart home?, cause you just found part of one!. This part is in charge of general resources like instructions to prepare the smart devices.
Stars: ✭ 18 (-14.29%)
Mutual labels:  hacktoberfest2020
hello-world-all-programming-language
This is a repository of examples of hello world programs in all programming languages
Stars: ✭ 23 (+9.52%)
Mutual labels:  hacktoberfest2020
Hacktoberfest-2020-Baby
No description or website provided.
Stars: ✭ 31 (+47.62%)
Mutual labels:  hacktoberfest2020
Hacktoberfest-Algorithms
This repository is mainly open to those who are looking to make some PRs for the Hacktoberfest 2020 event. In this repository, you can add programs on some useful algorithms for Competitive Programming in any languages.
Stars: ✭ 47 (+123.81%)
Mutual labels:  hacktoberfest2020

Web -- A Web Application foundation for Raku Build Status

Introduction

Web is a simple web application library set for Raku, that uses the PSGI interface. It is based on work done for the original Web.pm project, as well as WebRequest, and November.

It consists of a few libraries, the most important of which are:

  • Web::Request

    Contains information about the HTTP request.

  • Web::Response

    Builds a PSGI compliant response.

  • Web::App

    A minimal web framework, uses backend engines (see below).

  • Web::App::Dispatch

    An extension of Web::App support advanced dispatch rules.

Web::Request

Web::Request is similar to CGI.pm or Plack::Request from Perl 5.

It supports P6SGI 0.7Draft (recommended), P6SGI 0.4Draft, PSGI Classic, SCGI standalone, FastCGI standalone, and mod-perl6. It can be forced to use standard CGI, but that's really not recommended. Currently only supports GET and non-multipart POST. We are planning on adding multi-part POST including file uploads, and some optional magic parameters similar to the ones in PHP.

Web::Response

An easy to use object that builds a P6SGI/PSGI compliant response. Supports some quick methods such as content-type() and redirect() to automatically create appropriate headers.

Web::App

Puts the above two together, along with a backend engine, and a context helper object, and makes building web apps really easy.

It supports any backend engine that provides a P6SGI/PSGI compliant interface, and a handle() method that takes a subroutine as a parameter (the subroutine must take a hash representing the environment), or an app() method that takes the aforementioned subroutine as a parameter, and a run() method to start processing requests.

See the list below for details of which libraries to use.

The context helper object provides wrappers to the Request and Response objects, including some magic functions that enable features otherwise not possible, such as a far more advanced redirect() method.

Web::App::Dispatch

Web::App::Dispatch is an extension of Web::App, that also supports advanced action dispatch based on rules.

Rather than supporting a single handler, you can have multiple rules, which will perform specific actions, including running handlers, based on environment variables such as the URL path, host, or protocol.

Actions can include redirection, setting content-type, adding headers, or calling a handler (either a code block, or an object with a handle() method.) A default handler can be called if no rules are matched.

Related Projects and Extensions

  • Web::App::MVC

    A MVC web framework built upon Web::App::Dispatch.

  • Web::App::Ballet

    A Dancer-like interface to Web::App::Dispatch. NOTE: This project will be merged with Bailador in the near future.

Requirements

Connector Engine Modules

None of the connector modules are required by default, so you'll need to install them yourself whichever one you want.

  • SCGI

    Offers the best integration with existing web servers, such as Apache, lighttpd, etc. It's like FastCGI, only simpler and faster.

  • FastCGI

    A complex and comprehensive protocol, the Raku implementation is considerably slower than SCGI, but offers more advanced features.

  • HTTP::Easy

    Web::App supports the HTTP::Easy::PSGI adapter, which provides a nice clean standalone HTTP server with PSGI application support. This provides GET and POST support including multipart/form-data.

  • HTTP::Server::Simple

    This library has not been tested, but Web::App should be able to work with the HTTP::Server::Simple::PSGI interface without any modifications.

Examples

Example 1

This is an example of the use of Web::App and it's wrapper magic. Handlers for Web::App are sent a special Web::App::Context object which wraps the Request and Response, and provides some extra magic that makes life a lot easier.

  use SCGI;
  use Web::App;

  my $scgi = SCGI.new(:port(8118));
  my $app = Web::App.new($scgi);

  my $handler = sub ($context) {
    given $context.path {
      when '/' {
        $context.content-type('text/plain');
        $context.send("Request parameters:");
        $context.send($context.req.params.fmt('%s: %s', "\n"));
        my $name = $context.get('name');
        if $name {
          $context.send("Hello $name");
        }
      }
      default {
        ## We don't support anything else, send them home.
        $context.redirect('/');
      }
    }
  }

  $app.run: $handler;

  ## End of script.

Example 2

This example is using Web::App::Dispatch and some of its many rules.

  class RedirectHandler {
    has $.site;
    method handle ($context) {
      $context.redirect($.site);
    }
  }

  use SCGI;
  use Web::App::Dispatch;
  
  my $scgi = SCGI.new(:port(8118));
  my $app  = Web::App::Dispatch.new($scgi);

  my $main = sub ($context) {
    $context.set-status(200);
    $context.content-type('text/plain');
    my $name = $context.get(:default<World>, 'name');
    $context.send("Hello $name");
  }

  $app.add(:handler($main), :default); ## Gets called if no other rules match.

  ## Let's add an object-based handler on the '/test' URL path.
  my $test = RedirectHandler.new(:site<http://huri.net>);
  $app.add(:path</test>, :handler($test));

  ## Another form of redirect, using an action rule.
  $app.add(:proto<http>, :redirect<https>);

  ## A slurp handler.
  $app.add(:path</slurp>, :slurp<./webroot/hello.text>);

  ## Send a file to the client browser.
  $app.add(:path</file>, :sendfile<./webroot/data.zip>);

  ## Okay, let's run the app.
  $app.run;

  ## End of script.

Example 3

This is an example of using Web::Request and Web::Response together with HTTP::Easy's PSGI adapter, without using Web::App as a wrapper.

  use HTTP::Easy::PSGI;
  use Web::Request;
  use Web::Response;

  my $http = HTTP::Easy::PSGI.new(); ## Default port is 8080.

  my $handler = sub (%env) {
    my $req = Web::Request.new(%env);
    my $res = Web::Response.new();
    $res.set-status(200);
    $res.add-header('Content-Type' => 'text/plain');
    $res.send("Request parameters:");
    $res.send($req.params.fmt('%s: %s', "\n"));
    my $name = $req.get('name');
    if $name {
      $res.send("Hello $name");
    }
    return $res.response;
  }

  $http.handle: $handler;

  ## End of script.

Further Examples

For more examples, including using other backends, more dispatch rules, and lots of other cool stuff, see the examples in the 'test' folder.

Install

Install directly from this repo using

zef install Web

or download this repo and do

zef install --deps-only .

if you want to try and contribute to it.

TODO

  • Finish testing framework, and write some tests.
  • Fix binary uploads. They need to use Buf instead of Str.
  • Add more pre-canned headers and automation to Web::Response. Sending files back to the client should be made easy.
  • Add more useful helpers to Web::App::Context.
  • I'm planning on refactoring Web::App::Dispatch into a collection of smaller components, with a more rubust routing system.

Authors

License

Artistic License 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].