iReporter app enables users (citizen) to bring any form of corruption to the notice of appropriate authorities and the general public. Visit app url: https://irepot.herokuapp.com
- 1. π Getting Started
- 2. π Authentication
- 3. API Versioning
- 4. HTTP Requests
- 5. HTTP Response Codes
- π 6. Resources
- 7. π License
NodeJS: https://nodejs.org
PostgreSQL: https://www.postgresql.org
-
To run app locally, make sure you have
nodejs,postgresinstalled. -
Clone repository or clone your own fork
git clone https://github.com/devdbrandy/iReporter.git cd iReporter cp .env.example .env npm install -
Create a PostgreSQL database for the project via
pgAdminor run the below command on your terminal:createdb -h localhost -p 5432 -U postgres ireporter
-
Configure
.envenvironment variable with your credentials -
Run migration
npm run migrate -
(Optional) Seed dummy data
npm run seed -
Two npm scripts are availiable to spin up the app server:
npm run devspin up the server without watching for any file changesnpm run watchwatches for any file changes and reloads the server
npm run build
To test or consume api locally, you can make use of Postman or Insomnia
Test specs are implemented using mocha + chai + sinon.
Make a duplicate of .env and rename to .env.test, then configure your test credentials.
Two npm scripts are available to run the test suite:
npm run mochaornpm run mocha:watch- The later watches for any file changes and runs the full test suite (without code coverage)npm test- Performs a single full test suite run, including instanbul code coverage reporting. Summary coverage reports are written to stdout, and detailed HTML reports are available in/coverage/index.html
Access to restricted API endpoints requires an access token, iReporter uses access tokens to associate API requests with your account. To obtain your access token, make a request along with username and password credentials to https://irepot.herokuapp.com/auth/login
Sample Response:
POST https://irepot.herokuapp.com/auth/login
HTTP/1.1
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": 200,
"data": [
{
"token": "...",
"user": {}
}
]
}The second part of the URI specifies the API version you wish to access in the format v{version_number}.
For example, version 1 of the API (most current) is accessible via:
https://irepot.herokuapp.com/api/v1All API requests are made by sending asecure HTTPS request using one of the following methods, depending on the being taken:
POSTCreate a resourcePATCHUpdate a resourceGETGet a resource or list of resourcesDELETEDelete a resource
For POST and PATCH requests, the body of your request may include a JSON payload.
Each response will be returned with one of the following HTTP status codes:
200OKThe request was successful400Bad RequestThere was a problem with the request (security, malformed)401UnauthorizedThe supplied API credentials are invalid403ForbiddenThe credentials provided do not have permissions to access the requested resource404Not FoundAn attempt was made to access a resource that does not exist in the API500Server ErrorAn error on the server occurred
| URI | HTTP Method | Description |
|---|---|---|
/auth/signup |
POST |
Account signup |
/auth/login |
POST |
Account login |
| URI | HTTP Method | Description |
|---|---|---|
/api/v1/users |
GET |
Fetch all users |
/api/v1/users/{id} |
GET |
Fetch a specific user resource |
/api/v1/users/{id} |
PUT |
Update a specific user resource |
/api/v1/records |
GET |
Fetch a list of all records |
/api/v1/red-flags |
GET |
Fetch all red-flag records |
/api/v1/red-flags/{id} |
GET |
Fetch a specific red-flag record |
/api/v1/red-flags |
POST |
Create a red-flag record |
/api/v1/red-flags/{id}/location |
PATCH |
Edit red-flag's location |
/api/v1/red-flags/{id}/comment |
PATCH |
Edit red-flag's comment |
/api/v1/red-flags/{id} |
DELETE |
Delete specific red-flag |
/api/v1/interventions |
GET |
Fetch all intervention records |
/api/v1/interventions/{id} |
GET |
Fetch a specific intervention record |
/api/v1/interventions |
POST |
Create an intervention record |
/api/v1/interventions/{id}/location |
PATCH |
Edit intervention's location |
/api/v1/interventions/{id}/comment |
PATCH |
Edit intervention's comment |
/api/v1/interventions/{id} |
DELETE |
Delete specific intervention |
The iReporter REST API is open-sourced software licensed under the MIT license.