简体   繁体   English

Akka-Http中的实体是什么?

[英]What is an entity in Akka-Http?

I am new to akka-http and building a basic server-client application in scala. 我是akka-http的新手,并在scala中构建基本的服务器 - 客户端应用程序。 The examples I looked at has the object "entity". 我看过的例子有“实体”这个对象。 Can someone please explain the concept underlying and why is it used and how is it useful? 有人可以解释基础概念,为什么使用它,它有什么用?

post {
    path("insert") {
      entity(as[Student]) {
        obj => complete {
          insertingstudent(obj)
          s"got obj with name ${obj.getName()}"
        }
      }

Thanks 谢谢

Can someone please explain the concept underlying and why is it used and how is it useful? 有人可以解释基础概念,为什么使用它,它有什么用?

entity is of type HttpEntity . entity的类型为HttpEntity From the comments of the code : 从代码的评论

Models the entity (aka "body" or "content") of an HTTP message. 模拟HTTP消息的实体(也称为“正文”或“内容”)。

It is an abstraction over the content of the HTTP request. 它是对HTTP请求内容的抽象。 Many times, when one sends an HTTP request, they provide a payload inside the body of the request. 很多时候,当一个人发送HTTP请求时,他们会在请求正文中提供一个有效负载。 This body can be in many format, popular ones are JSON and XML. 这个主体可以是多种格式,流行的是JSON和XML。

When you write: 当你写:

entity(as[Student])

You are attempting to unmarhsall, or deserialize, the body of the request into a data structure of your liking. 您试图将请求的主体unmarhallall或反序列化为您喜欢的数据结构。 That means that your obj field in the proceeding function will be of type Student . 这意味着前进函数中的obj字段将为Student类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM