Skip to content
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

docs: Add REST endpoints documentation #13

Merged
merged 6 commits into from
Oct 15, 2024

Conversation

ashutoshgautams
Copy link
Contributor

What

This PR adds comprehensive documentation for the REST API endpoint (snapwp/v1/env) used in the SnapWP Helper plugin.

Why

Documentation is crucial for developers who want to integrate with or extend our plugin. This PR addresses the lack of detailed REST API documentation, making it easier for developers to understand and use our endpoint.

Related Issue(s):

How

  1. Created a new docs/rest-api.md file with detailed documentation for the snapwp/v1/env endpoint.
  2. Updated the README.md file to include a link to the new REST API documentation.

The documentation covers:

  • Endpoint URL and method
  • Authentication requirements
  • Request parameters and structure
  • Supported variables
  • Response formats (success and error)
  • Usage notes and examples

Testing Instructions

  1. Review the new docs/rest-api.md file to ensure all information is accurate and complete.
  2. Check the README.md file to confirm the new link to the REST API documentation is present and correct.
  3. (Optional) Test the documented endpoint to verify that the information provided matches the actual behavior.

Screenshots

N/A (Documentation changes only)

Additional Info

N/A

Checklist

  • I have read the Contribution Guidelines.
  • My code is tested to the best of my abilities.
  • My code passes all lints (PHPCS, PHPStan, ESLint, etc).
  • My code has detailed inline documentation.
  • I have added unit tests to verify the code works as intended.
  • I have updated the project documentation accordingly.

@ashutoshgautams ashutoshgautams self-assigned this Oct 5, 2024
docs/rest-api.md Show resolved Hide resolved
@ashutoshgautams ashutoshgautams marked this pull request as draft October 8, 2024 07:36
README.md Outdated Show resolved Hide resolved
docs/rest-api.md Outdated Show resolved Hide resolved
docs/rest-api.md Outdated Show resolved Hide resolved
docs/rest-api.md Outdated Show resolved Hide resolved
docs/rest-api.md Outdated Show resolved Hide resolved
docs/rest-api.md Outdated Show resolved Hide resolved
ashutoshgautams and others added 2 commits October 10, 2024 17:52
- Remove unnecessary elements
- Check & verify everything is accurate.
@ashutoshgautams ashutoshgautams marked this pull request as ready for review October 14, 2024 09:32
docs/rest-api.md Outdated
Comment on lines 35 to 75
### Testing Instructions

To verify the functionality of this endpoint, you can use any API testing tool (e.g., cURL, Postman, or a custom script). Follow these steps:

1. **Set up the request**:
* Create a new GET request.
* Set the URL to: `https://your-wordpress-site.com/wp-json/snapwp/v1/env`

2. **Set up Authentication**:
* Use Basic Auth with your WordPress username and the application password you generated.

3. **Set up Request Body**:
* In the "Body" tab, select "raw" and choose "JSON" from the dropdown.
* In the request body, enter the following JSON:
```json
{
"variables": [
{
"name": "NEXT_URL",
"value": "http://localhost:3000"
},
{
"name": "HOME_URL",
"value": "https://headless-demo.local"
},
{
"name": "GRAPHQL_ENDPOINT",
"value": "wp-graphql"
}
]
}
```

4. **Send the Request and Verify Responses**:
* Send the request and verify that you receive a 200 OK response.
* Check that the response body matches the example in the documentation.

5. **Test Error Cases**:
* Remove all variables from the request body and send the request. Verify that you receive a 400 Bad Request response matching the documentation.
* Remove one of the required variables (e.g., NEXT_URL) and send the request. Verify that you receive a 500 Internal Server Error response matching the documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, these are usage docs for developers. Teaching readers how to use REST is beyond the scope. Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this and added an example curl request.

docs/rest-api.md Outdated
Comment on lines 24 to 33
### Authentication

This endpoint requires administrator privileges. To authenticate:

1. In your WordPress admin panel, go to Users -> Your Profile.
2. Scroll down to the "Application Passwords" section.
3. Enter a name for your application password (e.g., "API Testing") and click "Add New Application Password".
4. Copy the generated password.

You'll use this password along with your username for Basic Auth when making requests.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the remaining unnecessary stuff I flagged, and this should be good to merge.

@justlevine justlevine merged commit 1660bc3 into develop Oct 15, 2024
8 checks passed
@justlevine justlevine deleted the docs/add-rest-endpoints-docs branch October 15, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Add docs on REST endpoint
2 participants