You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Add guide for local API setup, update api-usage slightly (#235)
* docs: Add API/OAuth 2 setup guide
Also rename api to api-usage
* docs: Cleanup api-usage page, add notes about 2.0
* docs: Apply suggestions from code review
Co-authored-by: Stuart Olivera <stuart@stuartolivera.com>
* docs: Reword API introduction to be more friendly
- Clarifies what Postman and Paw are, with links to their product pages
- Notes that this process works for remote instances as well, not just localhost
- Removed trailing whitespace and extra newlines
- Fixed a single typo
* Verbiage and HM typo fixes
* Added .DS_Store to .gitignore
Co-authored-by: Stuart Olivera <stuart@stuartolivera.com>
This page will show you how to simulate API requests with [Postman](https://www.postman.com/) or [Paw](https://paw.cloud/).
7
+
8
+
These programs allow you to run API requests (`GET`, `POST`, and so on) in an isolated environment, which is much easier to debug in compared to an iOS or Android app, for example.
9
+
10
+
In order to make requests in either Postman or Paw, you need to setup _OAuth 2 authorization_, as in HackathonManager, each request needs to be authorized first. This guide discusses how to enable OAuth 2 for these apps.
11
+
12
+
This guide assumes you have already setup an admin account on a local HackathonManager instance. For more details on this, see the [main README](https://github.com/codeRIT/hackathon-manager#local-development).
13
+
14
+
> To make API requests on a live/remote instance, simply replace `localhost` in all following commands with your HackathonManager's URL.
15
+
16
+
Select an app below to jump directly to its guide:
17
+
18
+
-[Connecting with Postman](#initial-setup-with-postman)
19
+
-[Connecting with Paw](#initial-setup-with-paw)
20
+
21
+
## OAuth2 Notes
22
+
23
+
- The application only supports `Authorization Code` and `Implicit Grant` authorization methods. It's suggested to use an `implicit` grant for native apps, as they are inherently trusted.
24
+
- In a real application, the callback URL should have a specific scope that's not just `http://`, i.e., `brickhack-ios://` (for BrickHack's iOS application). However Postman would really be confused with that scheme, so for local development, it's not advised.
25
+
- Client credentials must be sent in the body.
26
+
- Browser authorization is currently not supported, at least in Postman. Not sure why! If you discover a reason, please open an Issue on the [Hackathon Manager](https://github.com/codeRIT/hackathon-manager) repo.
27
+
28
+
## Connecting with Postman
29
+
30
+
In HackathonManager, sign in to your admin account and click "Manage". Then, at the bottom left of the sidebar, click the **Doorkeeper** tab.
Name it whatever you wish. Set the Redirect URI to `http://localhost:3000/apply`, uncheck `Confidential`, and set a scope to `main`. Then, click `Submit`.
37
+
38
+
> Note: There is [a bug](https://github.com/doorkeeper-gem/doorkeeper/issues/1307) in the current version of doorkeeper (5.0), where if you do not put a scope, all OAuth requests fail. This scope can be anything as long as it is not empty.
39
+
40
+
Now, go to Postman and configure the initial request as follows:
That's it! Now you can make authorized requests at whatever permission level your account has.
61
+
62
+
<imgsrc="assets/api-setup/postman5.png" />
63
+
64
+
## Connecting with Paw
65
+
66
+
The process is very similar to above. To save time, here is a screenshot of the `auth` config screen:
67
+
68
+
<imgsrc="assets/api-setup/paw1.png" />
69
+
70
+
To reset your login, remove the dynamic fields in `Refresh Token` and `Token`. If your web login is still cached, try clearing cookies (`Paw > Web Views > Clear Cookies`) and Cache (`Paw > Web Views > Clear Cache`).
Copy file name to clipboardExpand all lines: docs/api-usage.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,41 +1,43 @@
1
1
---
2
-
id: api
2
+
id: api-usage
3
3
title: API Usage
4
4
---
5
5
6
-
Almost all of the functionality exposed to users can also be accessed as an API with OAuth credentials. This includes both public- and management-facing functionality.
6
+
## Introduction
7
7
8
-
**Please note:** HackathonManager's primary audience is the web interface.
8
+
Almost all of the functionality exposed to users can also be accessed as an API with OAuth credentials. This includes both public and management-facing functionality.
9
9
10
-
While functionality may co-exist for both browser and API usage, API-style support might be a little rough around some edges. If you stumble upon something that works a little different than usual (e.g. returns HTML instead of JSON), open an issue and we can figure it out.
10
+
**Please note:** HackathonManager's primary audience is the web interface. The API is currently being rewritten to support more application-based functionality, however this is still a work in progress, and not all functions will be supported on version `2.0`.
11
11
12
-
## Endpoints
12
+
If you run into any inconsistencies, feel free to open an issue on the [hackathon-manager](https://github.com/codeRIT/hackathon-manager) repo.
13
13
14
-
Endpoints are shared with regular page controllers for browser-style functionality. This leverages Ruby on Rails routing (for a deep dive, see [Rails Routing from the Outside In](https://guides.rubyonrails.org/routing.html)).
14
+
## Endpoints
15
15
16
-
For example, listing bus lists:
16
+
> Note that endpoints are currently being rewritten to support more user-based access, rather than hiding most information under an admin-level restriction.
- API endpoint: https://apply.brickhack.io/manage/bus_lists.json
18
+
Endpoints are shared with regular page controllers for browser-style functionality. This leverages Ruby on Rails routing (for a deep dive, see [Rails Routing from the Outside In](https://guides.rubyonrails.org/routing.html)).
20
19
21
20
Because Rails follows a standard CRUD-format, these endpoints become very REST-like.
22
21
23
22
For example:
24
23
25
-
- List all tags: `GET https://apply.brickhack.io/manage/trackable_tags.json`
26
-
- View specific tag: `GET https://apply.brickhack.io/manage/trackable_tags/1.json`
27
-
- Create tag: `POST https://apply.brickhack.io/manage/trackable_tags.json` (with a JSON body of parameters)
28
-
- Update tag: `PATCH https://apply.brickhack.io/manage/trackable_tags/1.json` (with a JSON body of parameters)
| List all tags |`GET https://your-hackathon.io/manage/trackable_tags.json`|
27
+
| View specific tag |`GET https://your-hackathon.io/manage/trackable_tags/1.json`|
28
+
| Create tag |`POST https://your-hackathon.io/manage/trackable_tags.json` (with body parameters) |
29
+
| Update tag |`PATCH https://your-hackathon.io/manage/trackable_tags/1.json` (with body parameters) |
30
+
| Delete tag |`DELETE https://your-hackathon.io/manage/trackable_tags/1.json`|
30
31
31
32
For a full list of endpoints, run `bin/rails routes` locally. This utility, provided by Ruby on Rails, lists all possible paths you can route too (along with their respective HTTP method).
32
33
33
-
**Note: datatable endpoints** are highly coupled to [Datatables](https://datatables.net) functionality and are not easy to use.
34
+
> Note: Datatable endpoints are highly coupled to [Datatables](https://datatables.net) functionality and are not easy to use.
35
+
36
+
> Note: The following endpoints are currently being rewritten to allow for less restrictions, i.e., bypassing the `/manage/`-level permission.
34
37
35
38
Example for questionnaire management endpoints:
36
39
37
40
```
38
-
...
39
41
Prefix Verb URI Pattern Controller#Action
40
42
datatable_manage_questionnaires POST /manage/questionnaires/datatable(.:format) manage/questionnaires#datatable
datatable_manage_checkins POST /manage/checkins/datatable(.:format)
55
-
...
56
57
```
57
58
58
-
## Request & response
59
+
## Request & Response
59
60
60
61
Most endpoints can operate with JSON requests & responses. Simply provide `.json` at the end of the URL to be returned JSON, and provide `Content-Type: application/json` when using POST or PATCH with a JSON body.
61
62
@@ -72,13 +73,11 @@ end
72
73
- This "show" endpoint is the natural mapping for something like `GET /manage/questionnaires/1.json`
73
74
- Because `respond_with` is used, it will return JSON when `.json` is used in the URL
74
75
75
-
# Authentication
76
-
77
-
Authentication is implemented with OAauth 2, provided by the [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) gem.
76
+
## Authentication
78
77
79
-
An OAuth app should be created by an admin at https://apply.your-hackathon.com/oauth/applications. From there, you can implement a standard OAuth 2 flow.
78
+
Authentication is implemented with OAauth 2, provided by the [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) gem. For full Doorkeeper endpoints + docs, see the [Doorkeeper wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/API-endpoint-descriptions-and-examples).
80
79
81
-
For Doorkeeper endpoints + docs, see https://github.com/doorkeeper-gem/doorkeeper/wiki/API-endpoint-descriptions-and-examples
80
+
See the [Setup Postman/Paw for API Testing](api-setup.md) page for information on using those tools for testing the API locally.
82
81
83
82
Once appropriate authentication credentials are retrieved, they should be provided on all API requests.
0 commit comments