### ZnWebSocketDelegate Example Setup
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-WebSocket-Core.package/ZnWebSocketDelegate.class/README.md
Demonstrates how to set up and run examples for ZnWebSocketDelegate with ZnServer. This involves starting the server, configuring logging, installing examples, and stopping the server.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnServer default logToTranscript.
ZnWebSocketDelegate installExamplesInDefaultServer.
ZnServer stopDefault.
```
--------------------------------
### Install Pharo 2.0 with VM
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
Downloads and installs Pharo 2.0 and its virtual machine using a script from get.pharo.org. This command uses curl and bash to automate the setup process.
```bash
# curl get.pharo.org/20+vm | bash
```
--------------------------------
### Install and Configure ZnServer
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-REST.package/ZnExampleStorageRestServerDelegate.class/README.md
Demonstrates how to start the default ZnServer, configure it to use ZnExampleStorageRestServerDelegate for the 'storage' path, and log server activity.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnServer default logToTranscript.
ZnServer default delegate
map: 'storage'
to: ZnExampleStorageRestServerDelegate new.
ZnServer stopDefault.
```
--------------------------------
### Start Default Zinc Server
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Starts the default Zinc HTTP server listening on the specified port. This is a basic setup for interactive experimentation.
```Smalltalk
ZnServer startDefaultOn: 1701.
```
--------------------------------
### ZnDispatcherDelegate Server Setup and URL Mapping
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP.package/ZnDispatcherDelegate.class/README.md
Demonstrates how to start a ZnServer and configure a ZnDispatcherDelegate to map incoming requests to specific handlers. It includes mapping a '/hello' route to return HTML and a '/counter' route to a 'counterApplication'.
```Smalltalk
(server := ZnServer startDefaultOn: 9090)
delgate: (ZnDispatcherDelegate new
map: '/hello' to: [ :request :response | response entity: (ZnEntity html: '
hello server
') ];
map: '/counter' to: [ :request :response | counterApplication handleRequest: request response: response ]).
```
--------------------------------
### ZnSingleThreadedServer Setup and Usage
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP.package/ZnSingleThreadedServer.class/README.md
Demonstrates how to configure and start a ZnSingleThreadedServer, including setting an authenticator and making a client request. This snippet shows basic server initialization and client interaction.
```Smalltalk
ZnSingleThreadedServer startDefaultOn: 1701.
ZnSingleThreadedServer default authenticator: (ZnBasicAuthenticator username: 'foo' password: 'secret').
ZnClient new username: 'foo' password: 'secret'; get: 'http://localhost:1701'.
```
--------------------------------
### Setup Test Server with ServerDo
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
A helper method to configure and manage a Zinc HTTP server instance for testing. It starts the server, sets a delegate, and ensures the server is stopped after the block of code executes, providing a controlled environment for tests.
```Smalltalk
withServerDo: block
| server |
server := ZnServer on: 1700 + 10 atRandom.
[
server start.
self assert: server isRunning & server isListening.
server delegate: MyFirstWebApp new.
block cull: server
]
ensure: [ server stop ]
```
--------------------------------
### ZnTestRunnerDelegate Initialization and Test Execution
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-Examples.package/ZnTestRunnerDelegate.class/README.md
Demonstrates how to initialize the ZnTestRunnerDelegate to start a server and how to make GET requests to specific test endpoints using ZnEasy.
```Smalltalk
ZnTestRunnerDelegate startInServerOn: 1701.
ZnEasy get: 'http://localhost:1701/sunit/ZnUtilsTest'.
ZnEasy get: 'http://localhost:1701/sunit/ZnUtilsTest/testBase64'.
```
--------------------------------
### Start and Configure Zinc HTTP Server
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Demonstrates how to start a default Zinc HTTP server on a specified port and enable logging to the transcript. This allows monitoring server activity.
```Smalltalk
ZnServer startDefaultOn: 8080.
ZnServer default logToTranscript.
```
--------------------------------
### Setup and Teardown Test Server with ServerDo
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
This helper method encapsulates the logic for starting, configuring, and stopping a Zinc server for testing purposes. It ensures the server is properly managed, even if errors occur during the test execution, by using an 'ensure:' block for cleanup.
```Smalltalk
withServerDo: block
| server |
server := ZnServer on: 1700 + 10 atRandom.
[
server start.
self assert: server isRunning & server isListening.
server delegate: MyFirstWebApp new.
block cull: server
]
ensure: [ server stop ]
```
--------------------------------
### Start and Interact with Zinc Server
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP.package/ZnServer.class/README.md
This snippet demonstrates how to start the default Zinc HTTP server on a specified port and then use ZnClient to make a GET request to that server.
```Smalltalk
ZnServer startDefaultOn: 1701.
```
```Smalltalk
ZnClient new get: 'http://localhost:1701'.
```
--------------------------------
### Install Pharo VM and Image
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Download and install a specific version of Pharo (e.g., 2.0) along with its virtual machine using a shell script. This command fetches the necessary files from get.pharo.org.
```shell
curl get.pharo.org/20+vm | bash
```
--------------------------------
### ZnClient Request Example
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP.package/ZnMultiThreadedServer.class/README.md
Demonstrates creating a ZnClient instance with authentication credentials and making a GET request to a specified URL. This shows how to interact with a Zinc server from a client perspective.
```Smalltalk
ZnClient new username: 'foo' password: 'secret'; get: 'http://localhost:1701'.
```
--------------------------------
### ZnServer Setup and Configuration
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-REST.package/ZnExampleSumRestCall.class/README.md
Provides Smalltalk code for starting, configuring, and stopping the ZnServer. It demonstrates how to delegate REST calls for a specific URI space to a handler class.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnServer default logToTranscript.
ZnServer default delegate
map: 'sum'
to: (ZnRestServerDelegate new
uriSpace: (ZnCallHierarchyRestUriSpace new
rootClass: ZnExampleSumRestCall;
yourself);
yourself).
ZnServer stopDefault.
```
--------------------------------
### Control Zinc Server with ZnImageExampleDelegate
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-Examples.package/ZnImageExampleDelegate.class/README.md
Demonstrates starting, installing the delegate, and stopping the Zinc server. This code snippet shows the basic lifecycle management for the web application using Zinc components.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnImageExampleDelegate installInDefaultServer.
ZnServer stopDefault.
```
--------------------------------
### Handle GET Request with Query Parameters
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Handles GET requests by inspecting the URI query parameters. If the 'raw' parameter is present, it serves the raw image data; otherwise, it serves the HTML page.
```Smalltalk
handleGetRequest: request
^ (request uri queryAt: #raw ifAbsent: [ nil ])
ifNil: [ ZnResponse ok: (ZnEntity html: self html) ]
ifNotNil: [ ZnResponse ok: self image ]
```
--------------------------------
### Start ZnServer with Monticello Delegate
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-FileSystem-Legacy.package/ZnMonticelloServerDelegate.class/README.md
Initializes and starts the default ZnServer, setting the ZnMonticelloServerDelegate and its target directory for Monticello packages.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnServer default delegate: ((ZnMonticelloServerDelegate new)
directory: (FileDirectory on: '/Users/sven/Tmp/monticello');
yourself).
```
--------------------------------
### Handle GET Request
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Processes incoming GET requests. It serves the main image if 'raw=true' is in the query, the previous image if 'previous=true' is present, or the main HTML page otherwise.
```Smalltalk
handleGetRequest: request
(request uri queryAt: #raw ifAbsent: [ nil ])
ifNotNil: [ ^ ZnResponse ok: self image ].
(request uri queryAt: #previous ifAbsent: [ nil ])
ifNotNil: [ ^ ZnResponse ok: self previousImage ].
^ ZnResponse ok: (ZnEntity html: self html)
```
--------------------------------
### Start ZnServer
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-Examples.package/ZnStaticFileServerDelegate.class/README.md
This snippet shows how to start the ZnServer with a specified port number. It assumes the default delegate has already been configured.
```Smalltalk
ZnServer startDefaultOn: 1701.
```
--------------------------------
### Configure and Start ZnServer with Static File Delegate
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-FileSystem-Legacy.package/ZnStaticFileServerDelegate.class/README.md
Demonstrates how to initialize and configure ZnServer to use ZnStaticFileServerDelegate for serving static files. It sets a URL prefix and the root directory for file serving, then starts the server.
```Smalltalk
ZnServer startDefaultOn: 1701.
ZnServer default delegate: ((ZnStaticFileServerDelegate new)
```
--------------------------------
### ZnSecureServer Configuration and Start
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-Zodiac-Core.package/ZnSecureServer.class/README.md
Configures and starts the ZnSecureServer, specifying the port, SSL certificate, logging behavior, and initiating the server process. This configuration block defines the server's operational parameters.
```ZnServer DSL
(ZnSecureServer on: 1443)
yourself.
certificate: '/home/sven/ssl/key-cert.pem';
logToTranscript;
start;
```
--------------------------------
### Start Zinc Static Server
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-Seaside.package/ZnZincStaticServerAdaptor.class/README.md
Starts the Zinc static file server on a specified port and serves files from a given directory. This is the primary method to launch the server.
```Smalltalk
ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/var/www/'
```
--------------------------------
### Run Startup Script
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Executes the Smalltalk startup script using the Pharo image to launch the web server.
```Shell
# ./pharo myfirstwebapp.image run.st
```
--------------------------------
### ZnServer Startup Script
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
A Smalltalk script to configure and start the ZnServer. It maps URLs to application handlers and sets up redirection.
```Smalltalk
ZnServer defaultOn: 8080.
ZnServer default logToStandardOutput.
ZnServer default delegate
map: 'image' to: MyFirstWebApp new;
map: 'redirect-to-image' to: [ :request | ZnResponse redirect: 'image' ];
map: '/' to: 'redirect-to-image'.
ZnServer default start.
```
--------------------------------
### ZnClient Invocation Examples
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-REST.package/ZnExampleSumRestCall.class/README.md
Demonstrates how to use the ZnClient in Smalltalk to make various types of REST requests to the /sum endpoint, including GET with query parameters, GET with path segments, and POST with an entity.
```Smalltalk
ZnClient new
url: ZnServer default localUrl;
addPathSegment: #sum;
queryAt: #numbers put: '1,2,3';
get.
```
```Smalltalk
ZnClient new
url: ZnServer default localUrl;
addPathSegment: #sum;
addPathSegment: '1';
addPathSegment: '2';
addPathSegment: '3';
get.
```
```Smalltalk
ZnClient new
url: ZnServer default localUrl;
addPathSegment: #sum;
entity: (ZnEntity text: '1,2,3');
post.
```
--------------------------------
### Example Log Output from HTTP GET
Source: https://github.com/svenvc/zinc/blob/master/doc/od-zn-40y-st.md
This represents the textual output observed in the Transcript after executing an HTTP GET request. It details connection establishment, request writing, response reading, and connection closure, including timing information for each step.
```Text
2020-08-14 14:04:00 022 Connection Established stfx.eu:80 146.185.177.20 121ms
2020-08-14 14:04:00 023 Request Written a ZnRequest(GET /small.html) 0ms
2020-08-14 14:04:00 024 Response Read a ZnResponse(200 OK text/html 113B) 29ms
2020-08-14 14:04:00 025 GET /small.html 200 113B 29ms
2020-08-14 14:04:00 026 Connection Closed 146.185.177.20:80
```
--------------------------------
### Define a Simple 'Hello World' Web Application
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Defines a Smalltalk class `MyFirstWebApp` that handles incoming HTTP requests. It returns 'Hello World!' for requests to '/image' and a 404 Not Found for other paths.
```Smalltalk
Object subclass: #MyFirstWebApp
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'MyFirstWebApp'.
handleRequest: request
request uri path = #image
ifFalse: [ ^ ZnResponse notFound: request uri ].
^ ZnResponse ok: (ZnEntity text: 'Hello World!')
```
--------------------------------
### Curl Command Line Examples
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-Examples.package/ZnKeyValueStoreDelegate.class/README.md
Demonstrates interaction with the key-value store API using curl commands, showing how to list, add, retrieve, and delete data.
```Shell
$ curl http://localhost:1701/kvstore
the key-value store is empty
$ curl -X PUT -d 'ABC' -H'Content-Type:text/plain' http://localhost:1701/kvstore/xyz
ABC
$ curl http://localhost:1701/kvstore/xyz
ABC
$ curl http://localhost:1701/kvstore
xyz = ABC
$ curl -X DELETE http://localhost:1701/kvstore/xyz
/kvstore/xyz
$ curl http://localhost:1701/kvstore/xyz
Not Found /kvstore/xyz
```
--------------------------------
### Assertion Failure REST API Endpoint
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-REST.package/ZnExampleStorageAssertionFailureRestCall.class/README.md
This GET endpoint is part of the Zinc project's example storage functionality. It is designed to intentionally cause an assertion failure, likely for testing or demonstration purposes.
```APIDOC
GET /storage/exception/assertion
Description: Causes an AssertionFailure.
Purpose: To simulate an assertion failure within the storage system for testing error handling.
Method: GET
Endpoint: /storage/exception/assertion
Parameters: None
Returns: Typically an error response indicating an assertion failure.
Error Conditions: AssertionFailure
```
--------------------------------
### Making Authenticated Requests
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Provides examples of making HTTP requests to a server protected by ZnBasicAuthenticator. The first example shows a successful authenticated GET request, while the second demonstrates accessing the server without credentials, which would typically result in a 401 Unauthorized response.
```Smalltalk
ZnEasy get: 'http://localhost:1701' username: 'admin' password: 'secret'.
ZnEasy get: 'http://localhost:1701'.
```
--------------------------------
### Configure and Start ZnServer
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This Smalltalk code configures and starts the ZnServer to handle HTTP requests. It maps specific URL paths to application logic, including serving an image and handling redirects.
```smalltalk
ZnServer defaultOn: 8080.
ZnServer default logToStandardOutput.
ZnServer default delegate
map: 'image' to: MyFirstWebApp new;
map: 'redirect-to-image' to: [ :request | ZnResponse redirect: 'image' ];
map: '/' to: 'redirect-to-image'.
ZnServer default start.
```
--------------------------------
### Run Smalltalk Script with Pharo
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This command executes a Smalltalk script file (e.g., run.st) using the Pharo image. It's used to start the configured web server or perform other application tasks.
```bash
# ./pharo myfirstwebapp.image run.st
```
--------------------------------
### ZnUnixSocketClient Invocation Example
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-UnixSocket.package/ZnUnixSocketClient.class/README.md
Demonstrates the simplest invocation of ZnUnixSocketClient to perform an HTTP GET request over a Unix Domain Socket. It specifies the socket path and the target URL.
```Smalltalk
ZnUnixSocketClient new
unixSocket: '/var/run/docker.sock';
get: 'http://localhost/v1.43/containers/json'.
```
--------------------------------
### Bash Script Configuration Example
Source: https://github.com/svenvc/zinc/blob/master/rsrc/wws/highlight/test.html
A basic Bash script structure, starting with a shebang and a configuration section marked by comments. This is a common pattern for setting up script variables and parameters.
```Bash
#!/bin/bash
###### BEGIN CONFIG
```
--------------------------------
### Pharo Image Display Example
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Demonstrates how to take a parsed Pharo image 'form' object, convert it into a graphical morph, and open it in a window. This is useful for visualizing images directly within the Pharo environment, especially during debugging.
```Smalltalk
MyFirstWebApp new form asMorph openInWindow.
```
--------------------------------
### ZnEasy Quick HTTP Requests
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Provides examples of using the ZnEasy API for making simple HTTP requests with minimal code. It demonstrates a basic GET request and specialized methods for fetching image resources.
```Smalltalk
ZnEasy get: 'http://zn.stfx.eu/zn/numbers.txt'.
ZnEasy getGif: 'http://homepage.mac.com/svc/ADayAtTheBeach/calculator.gif'.
ZnEasy getJpeg: 'http://caretaker.wolf359.be/sun-fire-x2100.jpg'.
ZnEasy getPng: 'http://pharo.org/files/pharo.png'.
```
--------------------------------
### Install Web App Configuration with Pharo
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This command installs a specific stable version of a web application configuration using the Pharo Smalltalk environment. It points to a remote configuration repository and specifies the desired version.
```bash
# ./pharo myfirstwebapp.image config http://www.smalltalkhub.com/mc/SvenVanCaekenberghe/MyFirstWebApp/main ConfigurationOfMyFirstWebApp --install=stable
```
--------------------------------
### Advanced Static File Server Setup
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Demonstrates a more complex configuration for the static file server, including enabling logging, setting default mime-type expirations for caching, and applying basic HTTP authentication.
```Smalltalk
(ZnServer startDefaultOn: 1701)
logToTranscript;
delegate: (ZnStaticFileServerDelegate new
directory: (FileDirectory on: '/var/www');
mimeTypeExpirations: ZnStaticFileServerDelegate
defaultMimeTypeExpirations;
yourself);
authenticator: (ZnBasicAuthenticator username: 'admin' password: 'secret').
```
--------------------------------
### Curl Command Line Interaction with Zinc Server
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Demonstrates interacting with a Zinc HTTP server using the Unix utility 'curl'. Examples cover GET, POST, PUT, and DELETE requests with JSON payloads and content type headers.
```Shell
$ curl http://localhost:1701/
[ ]
$ curl -X POST -d '[1,2,3]' -H'Content-type:application/json' http://localhost:1701/
"Created /1"
$ curl http://localhost:1701/1
[
1,
2,
3
]
$ curl -X POST -d '{"bar":-2}' -H'Content-type:application/json' http://localhost:1701/
"Created /2"
$ curl http://localhost:1701/2
{
"bar" : -2
}
$ curl -X PUT -d '{"bar":-1}' -H'Content-type:application/json' http://localhost:1701/2
"Updated /2"
$ curl http://localhost:1701/2
{
"bar" : -1
}
$ curl http://localhost:1701/
[
"/1",
"/2"
]
$ curl -X DELETE http://localhost:1701/2
"Deleted /2"
$ curl http://localhost:1701/2
Not Found /2
```
--------------------------------
### Base64 Encoding and Decoding Examples
Source: https://github.com/svenvc/zinc/blob/master/doc/od-zn-40y-st.md
Illustrates Base64 encoding and decoding operations using both direct method calls on support objects and convenience messages added to standard classes.
```Smalltalk
ZnBase64Encoder new encode: #[ 0 1 2 3 4 5 6 7 8 9 ].
#[ 0 1 2 3 4 5 6 7 8 9 ] base64Encoded.
```
```Smalltalk
ZnBase64Encoder new decode: 'AAECAwQFBgcICQ=='.
'AAECAwQFBgcICQ==' base64Decoded.
```
--------------------------------
### Zinc Client Accept Header and Content Enforcement
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Shows how to configure ZnClient to specify the desired 'Accept' header and enforce that the server returns content matching the specified MIME type. It includes an example of a GET request and handling potential ZnUnexpectedContentType exceptions.
```Smalltalk
ZnClient new
enforceAcceptContentType: true;
accept: ZnMimeType textPlain;
get: 'http://zn.stfx.eu/zn/numbers.txt'.
```
--------------------------------
### Simple Server Delegate
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Configures the default Zinc server to respond with 'Hello World!' to any request using a simple block delegate.
```Smalltalk
(ZnServer startDefaultOn: 1701)
onRequestRespond: [ :request |
ZnResponse ok: (ZnEntity text: 'Hello World!') ].
```
--------------------------------
### Introduction to Zinc HTTP Components
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This section introduces the Zinc HTTP Components framework as the foundational tool for building web applications in Pharo. It highlights how Zinc abstracts HTTP concepts for easier coding and emphasizes the benefits of Pharo's dynamic nature for web development.
```APIDOC
Framework: Zinc HTTP Components
Purpose: Foundational framework for building web applications in Pharo.
Key Features:
- Abstracts HTTP concepts and related open standards.
- Facilitates easier coding by using nice objects.
Related Frameworks (Pharo):
- Seaside
- AIDAweb
- Iliad
Core Concepts:
- HTTP fundamentals
- Web application mechanics
- Dynamic, interactive nature of Pharo
- Rich IDE and library benefits
```
--------------------------------
### Smalltalk Object Method and Array Manipulation
Source: https://github.com/svenvc/zinc/blob/master/rsrc/wws/highlight/test.html
A Smalltalk method example showing object iteration using 'do:', variable declaration, object instantiation, array creation and manipulation, and a return statement. It also includes a 'heapExample' method with sorting setup.
```Smalltalk
Object>>method: num
"comment 123"
| var1 var2 |
(1 to: num) do: [:i | |var| ^i].
Klass with: var1.
Klass new.
arr := #('123' 123.345 #hello Transcript var $@).
arr := #().
var2 = arr at: 3.
^ self abc
heapExample
"HeapTest new heapExample"
"Multiline
decription"
| n rnd array time sorted |
n := 5000.
"# of elements to sort"
rnd := Random new.
array := (1 to: n)
```
--------------------------------
### Smalltalk Client Example
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP-Examples.package/ZnReadEvalPrintDelegate.class/README.md
Demonstrates how to use the ZnClient to connect to the REPL web service and send Smalltalk code for evaluation.
```Smalltalk
ZnReadEvalPrintDelegate startInServerOn: 1701.
ZnClient new
url: 'http://localhost:1701/repl';
contents: '42 factorial';
post.
```
--------------------------------
### RenderMan RIB Scene Description
Source: https://github.com/svenvc/zinc/blob/master/rsrc/wws/highlight/test.html
A RenderMan Interface By Example (RIB) file snippet describing a scene setup. It includes frame begin/end, display settings, search path options, trace options, visibility attributes, format, shading rate, pixel filter, projection, and archive loading for geometry and materials.
```RenderMan RIB
FrameBegin 0
Display "Scene" "framebuffer" "rgb"
Option "searchpath" "shader" "+&:/home/kew"
Option "trace" "int maxdepth" [4]
Attribute "visibility" "trace" [1]
Attribute "irradiance" "maxerror" [0.1]
Attribute "visibility" "transmission" "opaque"
Format 640 480 1.0
ShadingRate 2
PixelFilter "catmull-rom" 1 1
PixelSamples 4 4
Projection "perspective" "fov" 49.5502811377
Scale 1 1 -1
WorldBegin
ReadArchive "Lamp.002_Light/instance.rib"
Surface "plastic"
ReadArchive "Cube.004_Mesh/instance.rib"
# ReadArchive "Sphere.010_Mesh/instance.rib"
# ReadArchive "Sphere.009_Mesh/instance.rib"
ReadArchive "Sphere.006_Mesh/instance.rib"
WorldEnd
FrameEnd
```
--------------------------------
### Execute Client-Side GET Request
Source: https://github.com/svenvc/zinc/blob/master/doc/od-zn-40y-st.md
Demonstrates a client-side GET request. It involves creating a URL object, initializing a request, setting connection options, establishing a network connection, writing the request to the stream, flushing, reading the response, and closing the connection.
```Smalltalk
url := 'http://stfx.eu/small.html' asUrl.
request := ZnRequest get: url.
request setConnectionClose.
connection := ZnNetworkingUtils socketStreamToUrl: url.
request writeOn: connection.
connection flush.
response := ZnResponse readFrom: connection.
connection close.
response.
```
--------------------------------
### ZnUrl Operation Examples
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-Resource-Meta-Core.package/ZnUrlOperation.class/README.md
Examples of concrete operations derived from ZnUrlOperation, illustrating subclassing for specific URL types.
```APIDOC
ZnUrl>>#retrieveContents:
- Description: Retrieves the contents of a resource described by a URL.
- Purpose: A common operation that depends on URL elements like the scheme.
- Subclasses:
- ZnHttpRetrieveContents: Handles retrieval for HTTP URLs.
- ZnFileRetrieveContents: Handles retrieval for file URLs.
- Inheritance: Inherits from ZnUrlOperation.
```
--------------------------------
### Simple GET Request with ZnClient
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Demonstrates the most basic way to perform an HTTP GET request using ZnClient, returning the response body as a String.
```Smalltalk
ZnClient new get: 'http://zn.stfx.eu/zn/small.html'.
```
--------------------------------
### Handle General Request (GET/POST)
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This method routes incoming requests based on the URI path and HTTP method. It delegates to specific handlers for GET and POST requests to the '/image' path.
```Smalltalk
handleRequest: request
request uri path = #image
ifTrue: [
request method = #GET
ifTrue: [ ^ self handleGetRequest: request ].
request method = #POST
ifTrue: [ ^ self handlePostRequest: request ] ].
^ ZnResponse notFound: request uri
```
--------------------------------
### Install ZnServerSentEventDelegate
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-Server-Sent-Events.package/ZnServerSentEventDelegate.class/README.md
Installs the ZnServerSentEventDelegate into the default ZnServer instance. This makes the Server-Sent Events functionality available on the server.
```Smalltalk
ZnServerSentEventDelegate installInServer: ZnServer default.
```
--------------------------------
### WebDAV Client Initialization and Operations
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-WebDAV.package/ZnWebDAVClient.class/README.md
Demonstrates how to initialize and use the ZnWebDAVClient to connect to a WebDAV server. It shows setting host, port, username, password, listing directory contents, uploading a file, and retrieving a file.
```Smalltalk
ZnWebDAVClient new
host: 'localhost';
port: 8000;
username: 'johndoe' password: 'secret';
list;
at: 'foo.txt' put: (ZnEntity text: 'Pharo Smalltalk');
at: 'foo.txt'.
```
--------------------------------
### Verify Pharo Image Version
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.md
Check the installed Pharo image version by executing a command within the Pharo environment. This confirms the installation was successful.
```shell
./pharo Pharo.image printVersion
```
--------------------------------
### Start Zinc Server with Logging
Source: https://github.com/svenvc/zinc/blob/master/doc/zinc-http-components-paper.md
Starts the default Zinc HTTP server on port 1701 and enables logging to the Transcript for monitoring server activities and requests.
```Smalltalk
(ZnServer defaultOn: 1701)
logToTranscript;
start.
```
--------------------------------
### Handle GET Request for Image/HTML
Source: https://github.com/svenvc/zinc/blob/master/doc/build-and-deploy-1st-webapp/build-deploy-1st-webapp.html
This method handles incoming GET requests. It checks the request URI for a 'raw' query parameter to serve either the raw image data or the HTML page.
```Smalltalk
handleGetRequest: request
^ (request uri queryAt: #raw ifAbsent: [ nil ])
ifNil: [ ZnResponse ok: (ZnEntity html: self html) ]
ifNotNil: [ ZnResponse ok: self image ]
```
--------------------------------
### Start ZnMultiThreadedServer on Port
Source: https://github.com/svenvc/zinc/blob/master/repository/Zinc-HTTP.package/ZnMultiThreadedServer.class/README.md
Initializes and starts the ZnMultiThreadedServer on a specified port. This is a fundamental step for making the server operational and ready to accept incoming connections.
```Smalltalk
ZnMultiThreadedServer startDefaultOn: 1701.
```