当前位置: 首页>>代码示例>>Scala>>正文


Scala Request类代码示例

本文整理汇总了Scala中org.http4s.Request的典型用法代码示例。如果您正苦于以下问题:Scala Request类的具体用法?Scala Request怎么用?Scala Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Request类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: StravaRoutes

//设置package包名称以及导入依赖的类
package com.mfglabs
package models
package external

import org.http4s.Http4s.uri
import org.http4s.{ Request, Method, Headers, Header }
import java.time.Instant

object StravaRoutes {
  def activities(activitiesPerPage: Int)(token: Strava.Token)(after: Instant) =
    Request(
      Method.GET,
      uri("https://www.strava.com/api/v3/activities")
        .withQueryParam("per_page", activitiesPerPage)
        .withQueryParam("after", after.getEpochSecond),
      headers = Headers(Header("Authorization", s"Bearer ${token.value}"))
    )
} 
开发者ID:MfgLabs,项目名称:PSUG,代码行数:19,代码来源:external.scala

示例2: ServiceSpec

//设置package包名称以及导入依赖的类
package org.mdoc.rendering.service

import org.http4s.{ Request, Uri }
import org.http4s.dsl._
import org.http4s.headers.`Content-Type`
import org.http4s.util.CaseInsensitiveString
import org.mdoc.common.model.{ Document, Format }
import org.mdoc.common.model.jvm.FormatOps
import org.scalacheck.Prop._
import org.scalacheck.Properties
import scodec.bits.ByteVector

object ServiceSpec extends Properties("Service") {

  property("docToResponse sets ContentType") = secure {
    Format.values.forall { format =>
      val doc = Document(format, ByteVector.view("".getBytes))
      val response = Service.docToResponse(doc).run

      response.headers.get(CaseInsensitiveString("content-type"))
        .contains(`Content-Type`(FormatOps.toMediaType(format)))
    }
  }

  property("showRequest") = forAll { (s: String) =>
    Service.showRequest(Request(uri = Uri(path = s))) ?= s"GET $s"
  }

  property("route: /") = secure {
    Service.route.run(Request()).run.status ?= NotFound
  }

  property("route: /render failure") = secure {
    val req: Request = Request(uri = Uri(path = "/render"), method = POST)
    val body = Service.route.run(req).run.body.runLast.run
      .flatMap(_.decodeAscii.right.toOption).getOrElse("")
    body ?= "Invalid JSON"
  }

  property("route: /render/pdf/test.pdf") = secure {
    val req = Request(uri = Uri(path = "/render/pdf/test.pdf"))
    Service.route.run(req).run.status ?= BadRequest
  }

  property("route: /version") = secure {
    Service.route.run(Request(uri = Uri(path = "/version"))).run.status ?= Ok
  }
} 
开发者ID:m-doc,项目名称:rendering-service,代码行数:49,代码来源:ServiceSpec.scala

示例3: TestClient

//设置package包名称以及导入依赖的类
package com.github.hgiddens.ausms
package telstra

import JsonHelpers._
import io.circe.Json
import io.circe.syntax._
import org.http4s.{ Charset, MediaType, OAuth2BearerToken, Request, Response }
import org.http4s.client.{ Client, DisposableResponse }
import org.http4s.dsl._
import org.http4s.headers.{ Authorization, `Content-Type` }
import scalaz.Kleisli
import scalaz.concurrent.Task

private[telstra] object TestClient {
  val key = "key"
  val secret = "secret"
  val accessToken = "g85MslKJGuDIPhOklSgNLbWFPu5g"
  val messageId = "48E48E5EB8125001D6154CADFA19DA48"

  private val jsonContentType = `Content-Type`(MediaType.`application/json`, Some(Charset.`UTF-8`))

  private def perform(req: Request): Task[Response] =
    req match {
      case GET -> Root / "v1" / "oauth" / "token" =>
        Ok().withBody(Json.obj("access_token" -> accessToken.asJson, "expires_in" -> "3599".asJson))

      case POST -> Root / "v1" / "sms" / "messages" =>
        (req.headers, req.headers) match {
          case (Authorization(Authorization(OAuth2BearerToken(`accessToken`))), `Content-Type`(`jsonContentType`)) =>
            Accepted().withBody(Json.obj("messageId" -> messageId.asJson))
        }

      case GET -> Root / "v1" / "sms" / "messages" / `messageId` =>
        req.headers match {
          case Authorization(Authorization(OAuth2BearerToken(`accessToken`))) =>
            Ok().withBody(Json.obj(
              "to" -> "0400000000".asJson,
              "receivedTimestamp" -> "2015-02-05T14:10:14+11:00".asJson,
              "sentTimestamp" -> "2015-02-05T14:10:12+11:00".asJson,
              "status" -> "DELIVRD".asJson
            ))
        }
    }

  def client: Client =
    Client(Kleisli(perform _).map(new DisposableResponse(_, Task.now(()))), Task.now(()))
} 
开发者ID:hgiddens,项目名称:au-sms,代码行数:48,代码来源:TestClient.scala

示例4: ProjectController

//设置package包名称以及导入依赖的类
package fairshare.backend.project

import java.util.UUID

import argonaut.Argonaut._
import argonaut.Json
import org.http4s.argonaut._
import org.http4s.dsl._
import org.http4s.{ HttpService, Request, Response }
import fairshare.backend.util.RequestValidation._
import fairshare.backend.util.JsonHelpers._

import scalaz.concurrent.Task

class ProjectController(commandHandler: ProjectCommandHandler, queryHandler: ProjectQueryHandler) {
  def create(request: Request): Task[Response] = bindFromRequest(
    request,
    "name" -> nonEmptyString,
    "motto" -> nonEmptyString
  ) { (name, motto) =>
      val id = ProjectId(UUID.randomUUID())

      commandHandler.create(id, name, motto).flatMap(
        _.fold(
          error => InternalServerError(error),
          fact => Ok(Json("id" := fact.subject))
        )
      )
    }.fold(
      errs => BadRequest(errs.asJson),
      success => success
    )

  def index(request: Request): Task[Response] = {
    val projects = queryHandler.getAll

    Ok(projects.asJson)
  }

}

object ProjectController {
  def service(controller: ProjectController): HttpService = HttpService {
    case req @ GET -> Root / "index" => controller.index(req)

    case req @ POST -> Root / "create" => controller.create(req)
  }

} 
开发者ID:artempyanykh,项目名称:fair-share,代码行数:50,代码来源:ProjectController.scala

示例5: UserRoute

//设置package包名称以及导入依赖的类
package com.onur.moviedb.route

import argonaut.Argonaut._
import com.onur.moviedb.domain._
import com.onur.moviedb.route.error.{HttpError => HE}
import com.onur.moviedb.user.UserCreation.UserCreationValidation
import com.onur.moviedb.user.{UserModule, UserService}
import org.http4s.Request
import org.http4s.argonaut61.ArgonautInstances
import org.http4s.rho.{RhoService, _}

import scalaz.{-\/, Failure, NonEmptyList, Success, \/-}

object UserRoute {
  lazy val route = new UserRoute(UserModule.userService).toService()
}

private class UserRoute private(userService: UserService) extends RhoService with ArgonautInstances {

  GET |>> Ok(userService.getUsers.map(_.asJson))

  GET / pathVar[UserId] |>> { (uid: UserId) =>
    Ok(userService.getUserById(uid).map(_.asJson))
  }

  POST ^ jsonOf[UserCreationValidation] |>> { (r: Request, input: UserCreationValidation) =>
    input match {
      case Success(user) =>
        userService.createUser(user).flatMap {
          case \/-(res) => Created(res.asJson)
          case -\/(err) => HE.s409("Email is already registered", NonEmptyList(err))
        }
      case Failure(errs) => HE.s400("Invalid account details", errs)
    }
  }
} 
开发者ID:onurzdg,项目名称:movie-db,代码行数:37,代码来源:UserRoute.scala

示例6: ModernLibsService

//设置package包名称以及导入依赖的类
package org.modernlibs

import io.circe.generic.auto._
import io.circe.syntax._
import org.http4s.circe.{jsonEncoder, jsonOf}
import org.http4s.dsl._
import org.http4s.{HttpService, Request}

class ModernLibsService(db: DB) {

  val modernLibsService = HttpService {
    case GET -> Root / "ml" / name => getPerson(name)
    case GET -> Root / "ml" => getPersons
    case [email protected] -> Root / "ml" => newPerson(r)
  }

  private def getPersons = {
    for {
      dbResult <- db.list()
      result <- dbResult.map(r => Ok(r.asJson)) | InternalServerError()
    } yield result
  }

  private def getPerson(name: String) = {
    for {
      dbResult <- db.find(name)
      result <- dbResult.map(_.fold(NotFound())(r => Ok(r.asJson))) | InternalServerError()
    } yield result
  }

  private def newPerson(r: Request) = {
    for {
      person <- r.as(jsonOf[Person])
      dbResponse <- db.save(person)
      response <- dbResponse.map {
        case 1 => Created()
        case _ => Conflict()
      } | InternalServerError()
    } yield response
  }
} 
开发者ID:rogern,项目名称:modernlibs,代码行数:42,代码来源:ModernLibsService.scala

示例7: Sources

//设置package包名称以及导入依赖的类
package com.joescii.scalaz.stream

import org.http4s.{Method, Request, Status, Uri}
import org.http4s.client.blaze.SimpleHttp1Client

import scalaz.{-\/, \/-}
import scalaz.concurrent.Task
import scalaz.stream.io
import scalaz.stream.Process

object Sources {
  lazy val fromFileSystem:Process[Task, String] = io.linesR("./logs/AWSLogs.log")

  private [this] val c = SimpleHttp1Client()
  private [this] val uri = Uri.uri("https://raw.githubusercontent.com/ozantunca/elb-log-analyzer/master/logs/AWSLogs.log")

  lazy val fromTehWebz:Process[Task, String] = {
    val t = c.fetch(Request(Method.GET, uri)){ res => res.status match {
      case Status.Ok => res
        .bodyAsText
        .runLog
    }}

    Process.await(t)(Process.emitAll)
  }
} 
开发者ID:joescii,项目名称:scalaz-stream-elb-logs,代码行数:27,代码来源:Sources.scala


注:本文中的org.http4s.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。