This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
I. Getting Started
wizawu edited this page Mar 9, 2023
·
4 revisions
Let's build a simple HTTP service, which returns colorful text.
- Install tyrian.
npm install -g tyrian
Make sure you have JDK (from 8 to 14) and gradle (6 or upper) installed as well.
- Initialize an empty project.
mkdir /tmp/app && cd /tmp/app
tyrian init
You can find package.json
and tsconfig.json
created under the current directory. Then modify dependencies
and mvnDependencies
in package.json
.
{
"dependencies": {
"ansicolor": "^1.1.100",
"core-js": "^3.27.2"
},
"mvnDependencies": {
"com.sparkjava:spark-core": "2.5.5",
"org.slf4j:slf4j-simple": "1.7.21"
}
}
- Install dependencies.
tyrian install
You can find Maven dependencies installed in lib
and NPM dependencies installed in node_modules
.
- Modify
src/main.ts
.
import "core-js/es/object"
import * as colors from "ansicolor"
const Spark = spark.Spark
Spark.get("/:color", (req, _) => {
const key = String(req.params(":color"))
const color = colors[key]
return color("Hello\n")
})
- Build and run
tyrian build main.ts
tyrian run main.js
You can test it in the command line.
curl http://127.0.0.1:4567/blue
curl http://127.0.0.1:4567/green
curl http://127.0.0.1:4567/red