Skip to content

Commit

Permalink
feat!: respect rest convention (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
c100k authored Mar 25, 2024
1 parent b557fbb commit 044a538
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ You can also directly test the server with cURL:

```sh
curl -v -H "Authorization: <apiKey>" http://localhost:9001/cd5331ba/runnables
curl -v -X POST -H "Authorization: <apiKey>" http://localhost:9001/cd5331ba/runnables/reboot/self
curl -v -X POST -H "Authorization: <apiKey>" http://localhost:9001/cd5331ba/runnables/stop/self
curl -v -X POST -H "Authorization: <apiKey>" http://localhost:9001/cd5331ba/runnables/self/reboot
curl -v -X POST -H "Authorization: <apiKey>" http://localhost:9001/cd5331ba/runnables/self/stop
```

## Creating your own server
Expand Down
4 changes: 2 additions & 2 deletions impl/http-server-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func main() {
rootPath := fmt.Sprintf("/%s/runnables", config.pathPrefix)

router.HandleFunc(rootPath, getRunnablesHandler(service)).Methods("GET")
router.HandleFunc(fmt.Sprintf("%s/reboot/{id}", rootPath), postRunnableRebootHandler(service)).Methods("POST")
router.HandleFunc(fmt.Sprintf("%s/stop/{id}", rootPath), postRunnableStopHandler(service)).Methods("POST")
router.HandleFunc(fmt.Sprintf("%s/{id}/reboot", rootPath), postRunnableRebootHandler(service)).Methods("POST")
router.HandleFunc(fmt.Sprintf("%s/{id}/stop", rootPath), postRunnableStopHandler(service)).Methods("POST")

headersCORS := handlers.AllowedHeaders([]string{AUTHORIZATION_HEADER, "Content-Type", "Origin"})
methodsCORS := handlers.AllowedMethods([]string{"GET", "HEAD", "OPTIONS", "POST"})
Expand Down
4 changes: 2 additions & 2 deletions spec/_generated/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
]
}
},
"/runnables/reboot/{id}": {
"/runnables/{id}/reboot": {
"post": {
"operationId": "Reboot",
"responses": {
Expand Down Expand Up @@ -533,7 +533,7 @@
]
}
},
"/runnables/stop/{id}": {
"/runnables/{id}/stop": {
"post": {
"operationId": "Stop",
"responses": {
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/RunnablesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class RunnablesController extends Controller {
* @param id
* @returns
*/
@Post('reboot/{id}')
@Post('{id}/reboot')
@SuccessResponse(201)
@Response<ErrorRes>(401, ERR_401, { message: ERR_401 })
@Response<ErrorRes>(403, ERR_403, { message: ERR_403 })
Expand All @@ -94,7 +94,7 @@ export class RunnablesController extends Controller {
* @param id
* @returns
*/
@Post('stop/{id}')
@Post('{id}/stop')
@SuccessResponse(201)
@Response<ErrorRes>(401, ERR_401, { message: ERR_401 })
@Response<ErrorRes>(403, ERR_403, { message: ERR_403 })
Expand Down

0 comments on commit 044a538

Please sign in to comment.