当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphql-rest-api-demo

授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 葛炜
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

GraphQL/REST API Demo

A demo of what an equivalent REST API and GraphQL API look like. This code is used in the first chapter of The GraphQL Guide by John Resig and Loren Sands-Ramshaw. Here's the GraphQL server's GraphiQL:

ch1.graphql.guide/graphql

Installation

To install you'll want to run npm install or yarn to install all of the Node modules.

Additionally, you'll need to have a copy of MongoDB running. If you're on OSX you can use Homebrew to install MongoDB by running: brew install mongodb. That should also start the database server in the background, as well. If it's not running you can run brew services start mongodb to start it.

You'll also want to populate the database with some data to test your queries. You can do this by running the mongo testdb command on the command-line and executing the following commands to create a new database, some collections, and the data inside of them:

db.users.insert({_id: "123", username: "jeresig", groupId: "dev"})
db.users.insert({_id: "456", username: "lorensr", groupId: "author"})
db.groups.insert({_id: "dev", name: "Developers"})
db.groups.insert({_id: "author", name: "Authors"})

By default the servers are expecting to find data on your local computer in a database named "testdb". You can configure this by changing the settings in models.js.

Data Models

Our data models representing the MongoDB database are in models.js. We use Mongoose to do the object modeling and provide a convenient way of accessing and mutating the data in the MongoDB collections.

REST API

The REST API is implemented using Node Express and provides a couple endpoints for accessing user data.

You can run it using:

node rest-server.js

You can access the REST API by opening your browser and visiting either of the following URLs:

GraphQL Server

The GraphQL server is implemented using Node Express, GraphQL.js, and GraphQL Express. It provides access to both the User and Group type.

You can run it using:

node graphql-server.js

You can access the GraphQL data by opening your browser and visiting the GraphiQL view at:

You should see a console interface into which you can run GraphQL queries and see their results. You should also be able to browse the full schema and see all of the types that are available to you and what data they provide.

  • 作为一位web开发人员,在使用REST API的时候,是否遇到过这样的问题:     1.调用一个API的时候,总是会返回一些不需要的信息。   2. 对于一个资源的调用,如果想获取到更多的信息,可能需要发送多次请求才能获取。 那么现在是时候了解一下GraphQL了。   一、什么是GraphQL?   GraphQL是FaceBook于2012年在内部开发的数据查询语言,在2015年开源,旨在提

  • OCA/rest-framework https://github.com/OCA/rest-framework/tree/13.0 rest-framework和odoo的集成 OCA/rest-framework这个rest-framework框架可以帮助我们在odoo框架的基础上快速开发符合restful规范的接口 1 全部模块如下 以下这些模块文件下都有对应的readme文件以及usage

  • Graphql是个什么鬼 自行 百度 维基 google,或参考羊羊提供的链接。 它其实是一种新的设计api的思维,和rest相比,不用构造多个api,一个api可以解决所有请求。 GraphQL is a new way to think about building and querying APIs. Rather than construct several REST requests t

 相关资料
  • graphql-api graphql-api helps you implement a robust GraphQL API in Haskell. By the time a query makes it to your handler you are dealing with strong, static types that make sense for your problem dom

  • graphql-api-koa GraphQL execution and error handling middleware written from scratch for Koa. Setup To install graphql-api-koa and the graphql peer dependency with npm, run: npm install graphql-api-ko

  • 使用REST,我们可以使用Swagger、RAML或其他技术来记录我们的API,并生成一个HTML文档,我们的消费者可以阅读该文档,而无需与服务器进行任何交互。 GraphQL是否存在类似的情况?是否有任何方法生成资源和属性的文档?

  • Setup $ yarn install && open http://localhost:4000 && yarn run start Medium: https://medium.com/@wesharehoodies/how-to-setup-a-powerful-api-with-nodejs-graphql-mongodb-hapi-and-swagger-e251ac189649?

  • Storm UI 守护程序提供了一个 REST API, 允许您与 Storm 集群进行交互, 其中包括检索 metrics(度量)数据和配置信息, 启动或停止 topologies(拓扑)的管理操作。 数据格式 该 REST API 返回 JSON 响应并支持 JSONP. 客户端可以传回一个回调查询参数, 以在回调函数中包装 JSON。 REST API allows CORS by defa

  • 问题内容: 此处的典型示例是Twitter的API。我从概念上了解REST API的工作原理,从本质上讲,它只是针对您的特定请求的服务器查询,然后您会在其中收到响应(JSON,XML等),很棒。 但是我不确定在后台如何使用流API。我了解如何食用。例如,使用Twitter收听回复。从响应中侦听数据,并在其中分批发送推文。在字符串缓冲区中建立块,然后等待换行指示Tweet的结束。但是他们正在做些什么