-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc: add categories * refactor: doc structure refactored * fix: package-lock.json removed * refactor: create outline sub-directories * refactor: rename test to testing
- Loading branch information
1 parent
2f0eb65
commit 0ffb4d6
Showing
46 changed files
with
230 additions
and
11,118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Client", | ||
"position": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "DSL", | ||
"position": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Cookies", | ||
"position": 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Headers", | ||
"position": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "HttpData", | ||
"position": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Endpoint", | ||
"position": 7 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Http", | ||
"position": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Middleware", | ||
"position": 9 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Request", | ||
"position": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Response", | ||
"position": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Server", | ||
"position": 8 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Config | ||
|
||
Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Socket", | ||
"position": 10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Work in progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Examples", | ||
"position": 7 | ||
} |
2 changes: 1 addition & 1 deletion
2
...te/docs/advanced-examples/_category_.json → ...xamples/advanced-examples/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"label": "Advanced Examples", | ||
"position": 3 | ||
"position": 2 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...s/zio-http-basic-examples/_category_.json → ...s/zio-http-basic-examples/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"label": "Basic Examples", | ||
"position": 2 | ||
"position": 1 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Getting Started | ||
|
||
## Http | ||
|
||
### Creating a "_Hello World_" app | ||
|
||
```scala | ||
import zhttp.http._ | ||
|
||
val app = Http.text("Hello World!") | ||
``` | ||
|
||
An application can be made using any of the available operators on `zhttp.Http`. In the above program for any Http request, the response is always `"Hello World!"`. | ||
|
||
### Routing | ||
|
||
```scala | ||
import zhttp.http._ | ||
|
||
val app = Http.collect[Request] { | ||
case Method.GET -> Root / "fruits" / "a" => Response.text("Apple") | ||
case Method.GET -> Root / "fruits" / "b" => Response.text("Banana") | ||
} | ||
``` | ||
|
||
Pattern matching on route is supported by the framework | ||
|
||
### Composition | ||
|
||
```scala | ||
import zhttp.http._ | ||
|
||
val a = Http.collect[Request] { case Method.GET -> Root / "a" => Response.ok } | ||
val b = Http.collect[Request] { case Method.GET -> Root / "b" => Response.ok } | ||
|
||
val app = a <> b | ||
``` | ||
|
||
Apps can be composed using the `<>` operator. The way it works is, if none of the routes match in `a` , or a `NotFound` error is thrown from `a`, and then the control is passed on to the `b` app. | ||
|
||
### ZIO Integration | ||
|
||
```scala | ||
val app = Http.collectM[Request] { | ||
case Method.GET -> Root / "hello" => ZIO.succeed(Response.text("Hello World")) | ||
} | ||
``` | ||
|
||
`Http.collectM` allow routes to return a ZIO effect value. | ||
|
||
### Accessing the Request | ||
|
||
```scala | ||
import zhttp.http._ | ||
|
||
val app = Http.collect[Request] { | ||
case req @ Method.GET -> Root / "fruits" / "a" => | ||
Response.text("URL:" + req.url.path.asString + " Headers: " + r.headers) | ||
case req @ Method.POST -> Root / "fruits" / "a" => | ||
Response.text(req.getBodyAsString.getOrElse("No body!")) | ||
} | ||
``` | ||
|
||
### Testing | ||
|
||
zhttp provides a `zhttp-test` package for use in unit tests. You can utilize it as follows: | ||
|
||
```scala | ||
import zio.test._ | ||
import zhttp.test._ | ||
import zhttp.http._ | ||
|
||
object Spec extends DefaultRunnableSpec { | ||
val app = Http.collect[Request] { | ||
case Method.GET -> Root / "text" => Response.text("Hello World!") | ||
} | ||
|
||
def spec = suite("http") ( | ||
testM("should be ok") { | ||
val req = ??? | ||
val expectedRes = resp => resp.status.toJHttpStatus.code() == Status.OK | ||
assertM(app(req))(expectedRes) // an apply method is added via `zhttp.test` package | ||
} | ||
) | ||
} | ||
``` | ||
|
||
```scala | ||
import zhttp.http._ | ||
|
||
val app = Http.collect[Request] { | ||
case req @ Method.GET -> Root / "fruits" / "a" => | ||
Response.text("URL:" + req.url.path.asString + " Headers: " + r.headers) | ||
case req @ Method.POST -> Root / "fruits" / "a" => | ||
Response.text(req.getBodyAsString.getOrElse("No body!")) | ||
} | ||
``` | ||
|
||
## Socket | ||
|
||
### Creating a socket app | ||
|
||
```scala | ||
import zhttp.socket._ | ||
|
||
private val socket = Socket.collect[WebSocketFrame] { | ||
case WebSocketFrame.Text("FOO") => ZStream.succeed(WebSocketFrame.text("BAR")) | ||
} | ||
|
||
private val app = Http.collect[Request] { | ||
case Method.GET -> Root / "greet" / name => Response.text(s"Greetings {$name}!") | ||
case Method.GET -> Root / "ws" => Response.socket(socket) | ||
} | ||
``` | ||
|
||
## Server | ||
|
||
### Starting an Http App | ||
|
||
```scala | ||
import zhttp.http._ | ||
import zhttp.service.Server | ||
import zio._ | ||
|
||
object HelloWorld extends App { | ||
val app = Http.ok | ||
|
||
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = | ||
Server.start(8090, app).exitCode | ||
} | ||
``` | ||
|
||
A simple Http app that responds with empty content and a `200` status code is deployed on port `8090` using `Server.start`. | ||
|
||
## Examples | ||
|
||
- [Simple Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/HelloWorld.scala) | ||
- [Advanced Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/HelloWorldAdvanced.scala) | ||
- [WebSocket Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/SocketEchoServer.scala) | ||
- [Streaming Response](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/StreamingResponse.scala) | ||
- [Simple Client](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/SimpleClient.scala) | ||
- [File Streaming](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/FileStreaming.scala) | ||
- [Authentication](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/Authentication.scala) | ||
|
||
|
||
|
Oops, something went wrong.