Git Product home page Git Product logo

zinc's Introduction

Zinc HTTP Components

Zinc HTTP Components is an open-source Smalltalk framework to deal with the HTTP networking protocol.

CI

Based on core classes modelling all main HTTP concepts, a full featured HTTP client and server are provided.

API

Here are a couple of simple examples to give an impression of the API. You start a default (easy to reference) HTTP server with just one line of code.

ZnServer startDefaultOn: 1701.

Now you can browse locally to http://localhost:1701 - in particular have a look at the /help section and /echo - these are part of a set of demonstration handlers.

Accessing the server that we just started from code is easy too.

ZnClient new 
  url: ZnServer default localUrl; 
  addPathSegment: #echo; 
  entity: (ZnEntity text: 'Hello'); 
  post.

This builds an HTTP POST to our server's /echo handler with a simple text as resource. The server will echo information about the request it received, including the text resource that you posted.

By default, the demonstration server has a couple of handlers, mostly for testing. You can add your own, to do additions (sum two numbers), for example.

ZnServer default delegate 
  map: #adder to: [ :request | | x y sum |
    x := (request uri queryAt: #x) asNumber.
    y := (request uri queryAt: #y) asNumber.
    sum := x + y.
    ZnResponse ok: (ZnEntity text: sum asString) ].

This creates a new handler /adder that will take 2 query arguments, converts them to numbers and returns the result of adding them together.

Using the full client, we can test our new functionality.

ZnClient new 
  url: ZnServer default localUrl; 
  addPathSegment: #adder;
  queryAt: #x put: 1;
  queryAt: #y put: 2;
  get.

This builds an appropriate request to our /adder and executes it. By entering the proper URL directly, this becomes a one liner.

'http://localhost:1701/adder?x=1&y=2' asUrl retrieveContents.

Documentation

Over the years, various documentation has been written about Zinc HTTP Components. Some of it is somewhat outdated. We list the most recent first.

The code base has decent class and method comments, as well as unit tests and examples.

The best starter documentation can be found in the Pharo Enterprise book.

In particular, in the following chapters:

A live website can be found at http://zn.stfx.eu. You can run part of this website locally.

The original Zinc HTTP Components paper.

The Building and deploying your first web app with Pharo tutorial.

There is a separate GemStone README.

Loading

Metacello new
  repository: 'github://svenvc/zinc/repository';
  baseline: 'ZincHTTPComponents';
  load.

Sven Van Caekenberghe

MIT Licensed

zinc's People

Contributors

akgrant avatar astares avatar dalehenrich avatar demarey avatar domesticmouse avatar fortizpenaloza avatar gcotelli avatar jbrichau avatar jecisc avatar labordep avatar mabdi avatar mumez avatar nickager avatar noha avatar sergestinckwich avatar stonesong avatar svenvc avatar theseion avatar vonbecmann avatar wilfred avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.