https://github.com/stepzen-dev/stepzen-rest-example
An example showing how to make a REST API available as GraphQL API through StepZen.
https://github.com/stepzen-dev/stepzen-rest-example
api graphql rest rest-api
Last synced: over 1 year ago
JSON representation
An example showing how to make a REST API available as GraphQL API through StepZen.
- Host: GitHub
- URL: https://github.com/stepzen-dev/stepzen-rest-example
- Owner: stepzen-dev
- License: mit
- Created: 2021-09-20T15:19:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-30T14:41:58.000Z (over 4 years ago)
- Last Synced: 2025-01-11T20:15:06.728Z (over 1 year ago)
- Topics: api, graphql, rest, rest-api
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StepZen REST Example
An example showing how to make a REST API available as GraphQL API through StepZen.
## Getting started
Before you're able to try out this example, you need to make sure that StepZen is installed on your local machine and that you're logged in. You can find how to do this in the [Getting Started with StepZen](https://stepzen.com/docs/quick-start) guide.
After cloning this repository you need to run the following command to start this example:
```
stepzen start
```
This will make a GraphQL API available at [http://localhost:5000/api/rest-example](http://localhost:5000/api/rest-example) with the GraphiQL Playground.
## Sending requests
This project is using [My JSON Server](https://my-json-server.typicode.com/) to create a free REST API based on the contents of `db.json` in this repository. You can view an example of this REST API [here](https://my-json-server.typicode.com/stepzen-samples/stepzen-rest-example), and as you can see it has the following endpoints:
- [/products](https://my-json-server.typicode.com/stepzen-samples/stepzen-rest-example/products)
- [/products/[id]/categories](https://my-json-server.typicode.com/stepzen-samples/stepzen-rest-example/products/1/categories)
- [/products/[id]/rating](https://my-json-server.typicode.com/stepzen-samples/stepzen-rest-example/products/1/rating)
Based on the configuration that is passed to StepZen in `index.graphql` and `schema/ecommerce/graphql`, the schema for the GraphQL API is constructed. You can query the GraphQL API in example with the following query:
```graphql
query GetProduct {
getProduct(id: 1) {
name
price
category {
name
}
rating {
average
}
}
}
```
This query will return product information from the REST API, by calling the endpoints `/products/1`, `/products/1/categories` and `/products/1/rating` and returning all this data in one JSON blob.
## Questions
Do you have any questions on this integration, or you want to check out other integrations you can make with [StepZen](https://stepzen.com/? Have a look at the website or join the [Discord channel](https://discord.com/channels/768229795544170506) for support.