Is it possible to implement a web site in Swift without using JavaScript? Yes, it is.
The trick is quite old and consists of generating the HTML page on the server. The idea is to avoid the use of JavaScript on the client, style the HTML with CSS, generate the pages with AWS Lambda, and serve the content with API Gateway. The persistency layer will be implemented with DynamoDB. We are going to use the Serverless framework to deploy our project on AWS.

Serverless Project Setup
We’re assuming you have followed the readme to set up all the requirements:
- AWS cli configured with your AWS account
- Docker
- Serverless
- Make
Clone the template project:
git clone https://github.com/Andrea-Scuderi/aws-serverless-swift-sprinter-template.git
cd aws-serverless-swift-sprinter-template
Then build the project:
./build.sh

./deploy.sh

Once the project is deployed on your AWS account, the endpoint is created.
Browse the generated URL with a web browser. The webform is up and running!

How Does It Work?
The Lambda provides a computational block in the AWS Serverless stack and interacts with DynamoDB to retrieve the data stored:

The HTML post content keeps track of the action sent from the browser and is translated by the Lambda to a CRUD
(Create, Read, Update, Delete) command for DynamoDB.
After updating the DB, the content is presented in the response web page.
The API Gateway acts as a proxy publishing the Lambda content as a web server.
The Serverless framework deploys the stacks to AWS.
Lambda in Swift
The Lambda is coded in Swift using the following frameworks:
- aws-lambda-swift-sprinter-nio-plugin: Implements the AWS custom runtime using Swift NIO.
- aws-sdk-swift: Interacts with DynamoDB.
- Plot: Renders the HTML.
- Bootstrap: CSS for HTML pages (JavaScript disabled).

The Lambda decodes the API Gateway proxy event and runs the WebController.
The WebController updates DynamoDB with the information received and renders the next HTML page.
The HTML page is returned as a response to the web client.
Using Plot to render the HTML
The WebController renders the HTML passing the record list to the presenter, which is responsible for rendering the right web page.

The present
function renders the main page with the content generated and evaluates the stateless action posted by the HTML client.


The HTML is created by composing a small function implemented with the Plot framework. The picture above is an example of a card.
Using aws-sdk-swift for DynamoDB
aws-sdk-swift is a Swift client for AWS and contains the client for DynamoDB. Here are some code snippets:

Conclusion
I hope to have generated some curiosity about server-side Swift and Swift-Sprinter.
Check out the GitHub repository and feel free to experiment. I look forward to seeing something nice!
Thanks for reading.