Skip to content

Commit

Permalink
Draft: Http request with BodyInit
Browse files Browse the repository at this point in the history
  • Loading branch information
a.khakimov authored and davesmith00000 committed Nov 21, 2024
1 parent 67bc50b commit 9374a45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tyrian/src/main/scala/tyrian/http/Http.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ object Http:
case (Body.PlainText(contentType, body), method) if !Set(Method.Get, Method.Head).contains(method) =>
headers.append("Content-Type", contentType)
requestInit.body = body
case (Body.File(contentType, body), method) if !Set(Method.Get, Method.Head).contains(method) =>
headers.append("Content-Type", contentType)
requestInit.body = body
case _ =>

requestInit.headers = headers
Expand Down
3 changes: 3 additions & 0 deletions tyrian/src/main/scala/tyrian/http/Models.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tyrian.http

import org.scalajs.dom.BodyInit

/** An Error will be returned if something goes wrong with an HTTP request. */
enum HttpError:
/** A BadRequest means that the provide request was not valid for some reason.
Expand Down Expand Up @@ -41,6 +43,7 @@ enum Body derives CanEqual:
* the content of the body
*/
case PlainText(contentType: String, body: String) extends Body
case File(contentType: String, body: BodyInit) extends Body

object Body:
def html(body: String): Body = Body.PlainText("text/html", body)
Expand Down

0 comments on commit 9374a45

Please sign in to comment.