-
Notifications
You must be signed in to change notification settings - Fork 10
Update all docs #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update all docs #173
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
73b4742
improve oauth docs
TheJolman 1600e1a
update api-testing.md
TheJolman e30caa9
update project-structure.md
TheJolman 9f412c0
remove cli docs from swagger docs
TheJolman 0300465
rm redundant import name
TheJolman a493f56
remove hardcoded host in swagger docs
TheJolman 70dbe1b
Merge branch 'main' into docs/update
GaballaGit 2d0f5f7
update docs route
TheJolman c45cd58
add note about curl
TheJolman 91d9391
add newline
TheJolman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,46 @@ | ||
| # Testing the API | ||
|
|
||
| Once the api is running (via `air` or running it manually), you can use `xh` or `curl` to test the api from the command line. You probably already have `curl` installed, but `xh` is provided in the dev shell. | ||
| We recommend using `xh` as it is the more modern option. | ||
| If you prefer to use a GUI instead, Postman is a popular option. | ||
| Once the api is running (via `air` or running it manually), you can use `xh` or `curl` to test the api from the command line. We recommend using `xh` over `curl`, and it's provided in the dev shell. | ||
| If you prefer to use a GUI, Postman is a popular option. | ||
|
|
||
| ## Using Swagger Documentation | ||
| ## Using OpenAPI/Swagger Documentation | ||
|
|
||
| The API includes comprehensive Swagger documentation that provides an interactive interface for exploring and testing endpoints. When the server is running, you can access the Swagger UI at: | ||
| The API includes comprehensive OpenAPI2 (Swagger) documentation that provides an interactive interface for exploring and testing endpoints. When the server is running, you can access the Swagger UI at: | ||
|
|
||
| ``` | ||
| http://localhost:8080/swagger | ||
| http://localhost:8080/docs | ||
| ``` | ||
|
|
||
| The Swagger documentation includes: | ||
| - Complete API endpoint documentation for all available routes | ||
| - Interactive forms to test API calls directly from the browser | ||
| - Request/response schemas and examples | ||
| - Parameter descriptions and validation rules | ||
|
|
||
| This is often the easiest way to explore the API and understand what endpoints are available without needing to dive into the source code. You can also use it to make test requests without needing to construct `curl` or `xh` commands manually. | ||
|
|
||
| ## Using `xh` and `curl` | ||
| These examples use `xh`, but you can get the equivalent `curl` command by appending the `--curl` flag to any example command. | ||
|
|
||
| ### Sending a GET request | ||
| The following requests will request an event called "event1" from the APIs `events` endpoint. You'll probably have to create this event yourself if you want to use this exact command (see the POST section below). | ||
| ```sh | ||
| # assuming the server is running on localhost:8080 | ||
| xh :8080/v1/events/event1 | ||
|
|
||
| # or with curl: | ||
| curl localhost:8080/v1/events/event1 | ||
| ``` | ||
| Both `xh` and `curl` send a GET request by default, so you don't need to specify which method to use. | ||
| Note: `curl` won't give you formatted output by default, so it might be helpful to pipe to `jq` (also provided in dev shell) to make it look pretty. | ||
| ### Sending a POST request | ||
| This creates a resource in the database that we can later query for with a GET request. | ||
| The OAuth2 middleware expects a `dev-token` passed with the Authorization middleware while in dev mode. See `oauth-authenticaion.md` for details. | ||
| ```sh | ||
| curl localhost:8080/v1/events/event1 | jq | ||
| xh post :8080/v1/board/officers -A bearer -a dev-token \ | ||
| full_name="Bob" \ | ||
| picture="example.com/picture.webp" \ | ||
| discord="discord.com/users/bob" \ | ||
| github="github.com/bob" \ | ||
| uuid="123" | ||
| ``` | ||
|
|
||
|
|
||
| ### Sending a POST request | ||
| ### Sending a GET request | ||
| This queries the database for the resource we just created: | ||
| ```sh | ||
| xh POST :8080/v1/events \ | ||
| uuid="event1" \ | ||
| location="tsu" \ | ||
| start_at="1712851200000" \ | ||
| end_at="1712851200000" \ | ||
| is_all_day:=false \ | ||
| host="ACM" | ||
|
|
||
| # same thing with curl: | ||
| curl -X POST localhost:8080/v1/events \ | ||
| -H 'content-type: application/json' \ | ||
| -H 'accept: application/json' \ | ||
| -d '{"uuid":"event1","location":"tsu","start_at":"1712851200000","end_at":"1712851200000","is_all_day":false,"host":"ACM"}' | ||
| xh :8080/v1/board/officers/123 | ||
| ``` | ||
|
|
||
| As you can see, `xh` provides a more concise way to do the same thing. | ||
| There are lots of other routes, check out the OpenAPI docs for more info. | ||
|
|
||
| ### Using fixtures | ||
| In the `fixtures` directory of this project, there's some JSON payloads that we can use for testing so we don't have to write them out each time. Feel free to create any that might be useful to yourself and/or the team. | ||
|
|
||
| Here's an example using one to send a POST request: | ||
| ```sh | ||
| xh POST :8080/v1/events @fixtures/event.json | ||
|
|
||
| # same thing with curl: | ||
| curl -X POST localhost:8080/v1/events \ | ||
| -H "Content-Type: application/json" \ | ||
| -d @payload.json | ||
| xh post :8080/v1/events -A -a dev-token @fixtures/event_create.json | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| package handlers | ||
|
|
||
| import ( | ||
| docs "github.com/acmcsufoss/api.acmcsuf.com/internal/api/docs" | ||
| "github.com/acmcsufoss/api.acmcsuf.com/utils" | ||
| "github.com/gin-gonic/gin" | ||
| swaggerFiles "github.com/swaggo/files" | ||
| ginSwagger "github.com/swaggo/gin-swagger" | ||
|
|
||
| "github.com/acmcsufoss/api.acmcsuf.com/internal/api/docs" | ||
| ) | ||
|
|
||
| func NewSwaggerHandler() gin.HandlerFunc { | ||
| docs.SwaggerInfo.Title = "ACM CSUF API" | ||
| docs.SwaggerInfo.Version = "1.0" | ||
| docs.SwaggerInfo.Host = "localhost:8080" | ||
| docs.SwaggerInfo.Schemes = []string{"http", "https"} | ||
| docs.SwaggerInfo.Description = utils.SwaggerDescription | ||
| return ginSwagger.WrapHandler(swaggerFiles.Handler) | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.