restheart 基本使用

本文介绍RestHeart——一个基于MongoDB的REST API框架,并通过示例演示如何使用docker-compose搭建环境,包括创建数据库、集合及添加数据等基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

restheart 是一个方便基于mongodb的restapi 开发框架

参考项目 https://github.com/rongfengliang/restheart-docker-compose

docker-compose 环境运行

  • docker-compose yaml 文件
version: '3'
networks:
   backend:
services:
   restheart:
      image: softinstigate/restheart
      container_name: restheart
      depends_on:
         - mongodb
      networks:
         - backend
      ports:
         - "8080:8080"
      # volumes:
      # - ./etc:/opt/restheart/etc:ro

   mongodb:
      image: mongo:3.6
      container_name: restheart-mongo
      environment:
            MONGO_INITDB_ROOT_USERNAME: restheart
            MONGO_INITDB_ROOT_PASSWORD: R3ste4rt!
      command: --bind_ip_all --auth
      volumes:
         - ./data:/data/db
      networks:
         - backend
      ports:
        - "27017:27017"

restheart配置:
  • 启动
docker-compose up -d
  • 访问
http://localhost:8080/browser/#/?hal=f

基本操作

  • 创建数据库

    使用httpie 工具

http -a 'admin:changeit' PUT localhost:8080/db desc='this is my first db created with restheart'

HTTP/1.1 201 Created
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: u5pxfezxze7mau2999yhjk60p4j1vnq864m5m05a711ool4x9
Auth-Token-Location: /_authtokens/admin
Auth-Token-Valid-Until: 2018-09-04T05:58:59.239Z
Content-Length: 0
Content-Type: application/json
Date: Tue, 04 Sep 2018 05:43:59 GMT
Etag: 5b8e1b9f5c404500080d1634
Keep-Alive: timeout=38
X-Powered-By: restheart.org
  • 创建集合
http -a 'admin:changeit' PUT localhost:8080/db/coll desc='my first collection created with restheart'

HTTP/1.1 201 Created
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: 148lrvqkmnl6k2mvxnoilpbv5p167xc3w7fqavbubvnsfekj3t
Auth-Token-Location: /_authtokens/admin
Auth-Token-Valid-Until: 2018-09-04T06:41:59.905Z
Content-Length: 0
Content-Type: application/json
Date: Tue, 04 Sep 2018 06:26:59 GMT
Etag: 5b8e25b35c404500080d1636
Keep-Alive: timeout=38
X-Powered-By: restheart.org
  • 添加集合
http -a 'admin:changeit' POST localhost:8080/db/coll name='RESTHeart' rating='cool'
HTTP/1.1 201 Created
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: 148lrvqkmnl6k2mvxnoilpbv5p167xc3w7fqavbubvnsfekj3t
Auth-Token-Location: /_authtokens/admin
Auth-Token-Valid-Until: 2018-09-04T06:43:40.028Z
Content-Length: 0
Content-Type: application/json
Date: Tue, 04 Sep 2018 06:28:40 GMT
Etag: 5b8e26185c404500080d1637
Keep-Alive: timeout=38
Location: http://localhost:8080/db/coll/5b8e2618c5a8c63d6b2839cd
X-Powered-By: restheart.org
  • 获取集合数据
http -a 'admin:changeit' GET localhost:8080/db/coll

参考资料

https://restheart.org/learn/tutorial/
https://github.com/rongfengliang/restheart-docker-compose

 
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值