Skip to content

Commit fea7b70

Browse files
committed
added REST and GraphQL samples
1 parent 5f338fd commit fea7b70

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

README.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ This sample is a variation of the Full-Stack MVC Todo sample described here: [To
4747

4848
## Folder Structure
4949

50-
- `/api`: the NodeJs Azure Function code used to provide the backend API, called by the Vue.Js client
50+
- `/api`: the NodeJs Azure Function code used to provide the backend API, called by the Vue.Js client.
51+
- `/api/rest`: contains the Azure Function the provides REST endpoint support
52+
- `/api/graphql`: contains the Azure Function the provides GraphQL endpoint support
53+
- `/api/prisma`: contains the Prisma model
5154
- `/client`: the Vue.Js client. Original source code has been taken from official Vue.js sample and adapted to call a REST or GraphQL client instead of using local storage to save and retrieve todos
5255

5356
## Install the dependencies
@@ -188,6 +191,98 @@ Take a look at the sample workflow in the `./github/workflow` folder to see how
188191

189192
After you have commited the changes to the workflow file, the CI/CD pipeline will run again automatically (You can verify it from the "Action" section of your GitHub repo). Once the pipeline has run, you should have a working website. Go to http://[your-swa-name].azurestaticapps.net, and enjoy!
190193

194+
### REST Endpoint
195+
196+
You can create, update and delete ToDos, that are then in turn stored in Azure SQL, completely via REST using the `/api/todo` endpoint. It support GET, POST, PATCH and DELETE methods. For example using cUrl:
197+
198+
To get all available todos
199+
```
200+
curl -s -X GET https://[your-swa-name].azurestaticapps.net/api/todo
201+
```
202+
203+
To get a specific todo
204+
```
205+
curl -s -X GET https://[your-swa-name].azurestaticapps.net/api/todo/123
206+
```
207+
208+
Create a todo
209+
```
210+
curl -H "Content-Type: application/json" -s -X POST https://[your-swa-name].azurestaticapps.net/api/todo/ -d '{"title":"hello world"}'
211+
```
212+
213+
Update todo
214+
```
215+
curl -H "Content-Type: application/json" -X PUT https://[your-swa-name].azurestaticapps.net/api/todo/123 -d '{"title":"world, hello!", "completed":true}'
216+
```
217+
218+
Delete todo
219+
```
220+
curl -X DELETE https://[your-swa-name].azurestaticapps.net/api/todo/123
221+
```
222+
223+
A sample of REST endpoint usage in a web page is available at `/client-rest.html` page.
224+
225+
### GraphQL Endpoint
226+
227+
The GraphQL endpoint is available at `https://[your-swa-name].azurestaticapps.net/api/todo/graphql` and it provides an interactive GraphQL playground. You can create, update and delete ToDos, that are then in turn stored in Azure SQL, completely via GraphQL.
228+
229+
To get all available todos
230+
```
231+
query {
232+
todoList {
233+
id, title, completed
234+
}
235+
}
236+
```
237+
238+
To get a specific todo
239+
```
240+
query {
241+
todo(id: 123) {
242+
id, title, completed
243+
}
244+
}
245+
```
246+
247+
Create a todo
248+
```
249+
mutation {
250+
addTodo(title: "hello world")
251+
{
252+
id,
253+
title,
254+
completed
255+
}
256+
}
257+
```
258+
259+
Update todo
260+
```
261+
mutation {
262+
updateTodo(id: 123, title: "world, hello")
263+
{
264+
id,
265+
title,
266+
completed
267+
}
268+
}
269+
```
270+
271+
Delete todo
272+
```
273+
mutation {
274+
deleteTodo(id: 123)
275+
{
276+
id,
277+
title,
278+
completed
279+
}
280+
}
281+
```
282+
283+
A sample of GraphQL endpoint usage in a web page is available at `/client-graphql.html` page.
284+
285+
191286
## Azure Static Web App
192287
193288
Azure Static Web App supports a Free tier which is absolutely great so that you can try them for free, but of course don't expect great performances. Initial REST API response will be in the 500 msec area. Keep this in mind if you are planning to use them for something different than testing. If you need better performance right now and cannot when for when Azure Static Web App will be out of preview, you can always deploy the REST API using plain Azure Functions where you can have amazing scalability and performance.

0 commit comments

Comments
 (0)