Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

I. Getting Started

wizawu edited this page Mar 9, 2023 · 4 revisions

Let's build a simple HTTP service, which returns colorful text.

  1. Install tyrian.
npm install -g tyrian

Make sure you have JDK (from 8 to 14) and gradle (6 or upper) installed as well.

  1. 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"
  }
}
  1. Install dependencies.
tyrian install

You can find Maven dependencies installed in lib and NPM dependencies installed in node_modules.

  1. 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")
})
  1. 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
Clone this wiki locally