Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sangria-graphql/sangria-akka-http-example
An example GraphQL server written with akka-http, circe and sangria
https://github.com/sangria-graphql/sangria-akka-http-example
Last synced: about 1 month ago
JSON representation
An example GraphQL server written with akka-http, circe and sangria
- Host: GitHub
- URL: https://github.com/sangria-graphql/sangria-akka-http-example
- Owner: sangria-graphql
- License: apache-2.0
- Created: 2015-07-27T19:46:29.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T13:18:25.000Z (3 months ago)
- Last Synced: 2024-09-17T16:35:34.768Z (3 months ago)
- Language: Scala
- Homepage: https://sangria-graphql.github.io
- Size: 181 KB
- Stars: 241
- Watchers: 17
- Forks: 100
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-graphql - sangria-akka-http-example - An example GraphQL server written with akka-http and [sangria](https://sangria-graphql.org/) (Examples / Scala Examples)
- awesome-list - sangria-akka-http-example - http, circe and sangria | sangria-graphql | 241 | (Scala)
README
## Sangria akka-http Example
An example [GraphQL](https://graphql.org) server written with [akka-http](https://github.com/akka/akka-http), [circe](https://github.com/circe/circe) and [sangria](https://github.com/sangria-graphql/sangria).
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
After starting the server with
```bash
sbt run# or, if you want to watch the source code changes
sbt ~reStart
```you can run queries interactively using [graphql-playground](https://github.com/prisma/graphql-playground) by opening [http://localhost:8080](http://localhost:8080) in a browser or query the `/graphql` endpoint directly. The HTTP endpoint follows [GraphQL best practices for handling the HTTP requests](http://graphql.org/learn/serving-over-http/#http-methods-headers-and-body).
Here are some examples of the queries you can make:
```bash
$ curl -X POST localhost:8080/graphql \
-H "Content-Type:application/json" \
-d '{"query": "{hero {name, friends {name}}}"}'
```this gives back the hero of StarWars Saga together with the list of his friends, which is of course R2-D2:
```json
{
"data": {
"hero": {
"name": "R2-D2",
"friends": [
{
"name": "Luke Skywalker"
},
{
"name": "Han Solo"
},
{
"name": "Leia Organa"
}
]
}
}
}
```Here is another example, which uses variables:
```bash
$ curl -X POST localhost:8080/graphql \
-H "Content-Type:application/json" \
-d '{"query": "query Test($humanId: String!){human(id: $humanId) {name, homePlanet, friends {name}}}", "variables": {"humanId": "1000"}}'
```The result should be something like this:
```json
{
"data": {
"human": {
"name": "Luke Skywalker",
"homePlanet": "Tatooine",
"friends": [
{
"name": "Han Solo"
},
{
"name": "Leia Organa"
},
{
"name": "C-3PO"
},
{
"name": "R2-D2"
}
]
}
}
}
```