zio / zio-quickstarts

A minimal quickstart ZIO application for writing a RESTful Web Service
https://zio.dev/guides/#quickstart-guides
60 stars 39 forks source link

Fix Issues in webservice quickstart #54

Closed damjad closed 1 month ago

damjad commented 2 months ago

The zio-quickstart-restful-webservice does not work as expected as mentioned in the documentation. https://zio.dev/guides/quickstarts/restful-webservice/

Issue 1:

For Download Routes, it's not returning the correctly formed output. Apparently, the fromStream method uses a binary encoder, and fromStreamChunked does not.

Expected output:

curl -i http://localhost:8080/download
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=file.txt
transfer-encoding: chunked

line number 1
1, 2, 3, 4, 5
line number 3
end of file

Actual Output

curl -i http://localhost:8080/download
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=file.txt
transfer-encoding: chunked

1081051101013211011710998101114324910494432504432514432524432531010810511010132110117109981011143251101011101003211110232102105108101

Issue 2:

For Greetings Routes, the logic of the routes is not correct. The /greet route does not return the correct response.

Expected Output

user@host ~> curl -i localhost:8080/greet
HTTP/1.1 200 OK
content-type: text/plain
content-length: 12

Hello World!

Actual Output

user@host ~> curl -i localhost:8080/greet
HTTP/1.1 400 Bad Request
warning: 199 ZIO HTTP "The name query parameter is missing!"
date: Thu, 16 May 2024 13:19:17 GMT
content-length: 0

Issue 3:

Moreover, the logic for handling multiple names is also incorrect.

Expected Output

user@host ~> curl -i localhost:8080/greet
HTTP/1.1 200 OK
content-type: text/plain
content-length: 12

Hello Danish and Amjad!

Actual Output

user@host ~> curl -i "localhost:8080/greet?name=Danish&name=Amjad"
HTTP/1.1 200 OK
content-type: text/plain
date: Thu, 16 May 2024 13:23:24 GMT
content-length: 71

Hello Chunk(D and a and n and i and s and h,A and m and j and a and d)!
CLAassistant commented 2 months ago

CLA assistant check
All committers have signed the CLA.