All Projects → pointfreeco → Swift Web

pointfreeco / Swift Web

Licence: mit
🕸 A collection of Swift server-side frameworks for handling HTML, CSS, routing and middleware.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swift Web

Swift Gen
🎱 Composable, transformable, controllable randomness.
Stars: ✭ 208 (-49.88%)
Mutual labels:  composition, functional-programming
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (-66.99%)
Mutual labels:  middleware, functional-programming
Reitit
A fast data-driven router for Clojure/Script
Stars: ✭ 892 (+114.94%)
Mutual labels:  middleware, routing
Json Decoder
Type safe JSON decoder for TypeScript
Stars: ✭ 67 (-83.86%)
Mutual labels:  composition, functional-programming
koii
A simple middleware for displaying routes in an express application
Stars: ✭ 73 (-82.41%)
Mutual labels:  middleware, routing
Not Awesome Es6 Classes
A curated list of resources on why ES6 (aka ES2015) classes are NOT awesome
Stars: ✭ 1,185 (+185.54%)
Mutual labels:  composition, functional-programming
Redux First Routing
A minimal, framework-agnostic API for accomplishing Redux-first routing.
Stars: ✭ 133 (-67.95%)
Mutual labels:  middleware, routing
Go Bootstrap
Easy way to bootstrap a web server in Go (Routing|Middleware|Https)
Stars: ✭ 27 (-93.49%)
Mutual labels:  middleware, routing
Clevergo
👅 CleverGo is a lightweight, feature rich and high performance HTTP router for Go.
Stars: ✭ 246 (-40.72%)
Mutual labels:  middleware, routing
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (-58.31%)
Mutual labels:  middleware, routing
Redash
Tiny functional programming suite for JavaScript.
Stars: ✭ 40 (-90.36%)
Mutual labels:  composition, functional-programming
Lambda Talk
A Flock of Functions: Combinators, Lambda Calculus, & Church Encodings in JS
Stars: ✭ 315 (-24.1%)
Mutual labels:  composition, functional-programming
Bugz
🐛 Composable User Agent Detection using Ramda
Stars: ✭ 15 (-96.39%)
Mutual labels:  composition, functional-programming
Functionalplus
Functional Programming Library for C++. Write concise and readable C++ code.
Stars: ✭ 1,286 (+209.88%)
Mutual labels:  composition, functional-programming
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+29.64%)
Mutual labels:  composition, functional-programming
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-59.04%)
Mutual labels:  middleware, routing
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-32.77%)
Mutual labels:  middleware, routing
Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (-16.63%)
Mutual labels:  composition, functional-programming
Functional Javascript
Functional is a library for functional programming in JavaScript. It defines the standard higher-order functions such as map, reduce (aka foldl), and select (aka filter). It also defines functions such as curry, rcurry, and partial for partial function application; and compose, guard, and until for function-level programming.
Stars: ✭ 383 (-7.71%)
Mutual labels:  functional-programming
Concurrency Logger
Log HTTP requests/responses separately, visualize their concurrency and report logs/errors in context of a request.
Stars: ✭ 400 (-3.61%)
Mutual labels:  middleware

swift-web

Swift 5.1 CI @pointfreeco

A collection of frameworks for solving various problems in building a Swift web framework. Each framework focuses on a single problem, like HTML rendering, CSS preprocessing, routing, middleware, and more. They also do not depend on any other framework in the collection. You can choose which pieces you want and don't want, for example you can use Html without Css.

Stability

This library should be considered alpha, and not stable. Breaking changes will happen often.

Installation

import PackageDescription

let package = Package(
  dependencies: [
    .package(url: "https://github.com/pointfreeco/swift-web.git", .branch("master")),
  ]
)

Getting started

This library contains an extensive test suite and a set of playgrounds that can be explored. To get it running:

  • git clone https://github.com/pointfreeco/swift-web.git
  • cd swift-web
  • swift package generate-xcodeproj
  • xed .
  • Run tests: Command+U
  • Build: Command+B
  • Open a playground!

Included modules

Primary modules

Supporting modules

Css

An EDSL for a CSS preprocessor like Sass. A few simple value types and functions allow you to model most of CSS, and allow you express new things not possible in standard CSS.

import Css

let css = body % (
  padding(all: .rem(2))
    <> background(Color.hsl(60, 0.5, 0.8))
)

render(css: css)
body {
  padding-top    : 2rem;
  padding-right  : 2rem;
  padding-bottom : 2rem;
  padding-left   : 2rem;
  background     : #e6e6b3;
}

HttpPipeline

A few types and functions for modeling server middleware as a simple function that transforms a request to a response. It uses phantom types express the state transitions of when you are allowed to write the status, headers and response body.

import HttpPipeline

let middleware = writeStatus(.ok)
  >>> writeHeader(.contentType(.html))
  >>> closeHeaders
  >>> send(render(document).data(using: .utf8))
  >>> end

let request = URLRequest(url: URL(string: "/")!)
let conn = connection(from: request).map(const(Data?.none))
▿ Step
  ResponseEnded

▿ Request
  GET /

  (Data, 0 bytes)

▿ Response
  Status 200 OK
  Content-Type: text/html; charset=utf8

  <html><body><p>Hello world!</p><p>Goodbye!</p><a href="/">Home</a></body></html>

ApplicativeRouter

A router built on the principles of “applicatives” that unifies parsing requests and printing routes. It is robust, composable and type-safe. Its job is to take the incoming, unstructured URLRequest from the browser and turn it into a structured value so that your app can do what it needs to do to produce a response. Additionally, given a value, it can do the reverse in which it generates a request that can be used in a hyperlink. Most of the ideas for this library were taking from this paper.

import ApplicativeRouter

struct UserData: Decodable {
  let email: String
}

enum Route {
  case home
  case episodes
  case episode(String)
  case search(String?)
  case signup(UserData?)
}

let router = [
  // Matches: GET /
  Route.iso.home
    <¢> .get <% end,

  // Matches: GET /episode/:str
  Route.iso.episode
    <¢> get %> lit("episode") %> pathParam(.string) <% end,

  // Matches: GET /episodes
  Route.iso.episodes
    <¢> get %> lit("episodes") <% end,

  // Matches: GET /search?query=:optional_string
  Route.iso.search
    <¢> get %> lit("search") %> queryParam("query", opt(.string)) <% end,

  // Matches: POST /signup
  Route.iso.signup
    <¢> post %> jsonBody(Episode.self) <%> lit("signup") %> opt(.jsonBody)) <% end,
  ]
  .reduce(.empty, <|>)

// Match a route given a request
let request = URLRequest(url: URL(string: "https://www.pointfree.co/episode/001-hello-world")!)
let route = router.match(request: request)
// => Route.episode("001-hello-world")

// Generate a string from a route:
router.absoluteString(for: .episode("001-hello-world"))
// => /episode/001-hello-world

HttpPipelineHtmlSupport

Adds middleware for rendering an Html view:

import Foundation
import Html
import HttpPipeline
import HttpPipelineHtmlSupport

let view = View(p(["Hello world!"]))

let middleware = writeStatus(.ok)
  >>> respond(view)

let conn = connection(from: URLRequest(url: URL(string: "/")!))
middleware(conn).response.description
Status 200
Content-Type: text/html

<p>Hello world!</p>

HtmlCssSupport

Adds an element and attribute function to Html for render Css values into an internal stylesheet or inline styles. The element function style allows you to provide a Stylesheet value that will be rendered to an internal stylesheet:

import Css
import Html
import HtmlCssSupport

let css = body % background(red)
let document = html([head([style(css)])])
render(document)
<html>
  <head>
    <style>body{background:#ff0000}</style>
  </head>
</html>

The attribute function style allows you to render a stylesheet inline directly on an element:

import Css
import Html
import HtmlCssSupport

let anchorStyle = color(.red)
  <> textTransform(.capitalize)

let styledDocument = p([
  "Go back ",
  a([style(anchorStyle)], ["Home"])
  ])

print(render(styledDocument, config: pretty))
<p>
  Go back
  <a style="color:#ff0000;text-transform:capitalize">
    Home
  </a>
</p>

CssReset

Contains a single value reset of type Stylesheet that resets all of the defaults for a webpage. It can be combined with another stylesheet via reset <> otherStyles, or can be directly rendered to a stylesheet string via render(reset).

License

All modules are released under the MIT license. See LICENSE for details.

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].