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

Restructure webservices #270

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Restructure webservices #270

wants to merge 4 commits into from

Conversation

pe7er
Copy link
Collaborator

@pe7er pe7er commented Jun 4, 2024

User description

This PR is to restructure the https://manual.joomla.org/docs/next/general-concepts/webservices page.

I refactored the documentation in

The internal links in Web Services Core Endpoints are not yet added.


PR Type

documentation


Description

  • Removed outdated web services documentation.
  • Added new introductory content about web services and links to Joomla's core endpoints and Postman collection.
  • Added detailed documentation for using PHP cURL functions with Joomla web services, including examples for CRUD operations on articles.
  • Added detailed documentation for using Joomla framework with web services, including examples for CRUD operations on articles.
  • Added comprehensive documentation for Joomla core web services endpoints, covering various components like banners, contacts, content, languages, menus, etc.

Changes walkthrough 📝

Relevant files
Documentation
webservices.md
Removed outdated web services documentation.                         

docs/general-concepts/webservices.md

  • Removed entire content of the file.
+0/-407 
index.md
Added introduction and links for web services.                     

docs/general-concepts/webservices/index.md

  • Added introductory content about web services.
  • Included links to Joomla's core endpoints and Postman collection.
  • +16/-0   
    using-external-php.md
    Added PHP cURL functions documentation for Joomla web services.

    docs/general-concepts/webservices/using-external-php.md

  • Added documentation for using PHP cURL functions with Joomla web
    services.
  • Included examples for CRUD operations on articles.
  • +202/-0 
    using-joomla-framework.md
    Added Joomla framework documentation for web services.     

    docs/general-concepts/webservices/using-joomla-framework.md

  • Added documentation for using Joomla framework with web services.
  • Included examples for CRUD operations on articles.
  • +189/-0 
    webservices-core-endpoints.md
    Added detailed documentation for Joomla core web services endpoints.

    docs/general-concepts/webservices/webservices-core-endpoints.md

  • Added detailed documentation for Joomla core web services endpoints.
  • Included examples for various components like banners, contacts,
    content, languages, menus, etc.
  • +1086/-0

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-merge-pro qodo-merge-pro bot added the documentation Improvements or additions to documentation label Jun 4, 2024
    Copy link
    Contributor

    qodo-merge-pro bot commented Jun 4, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    4, due to the extensive changes across multiple files and the complexity of the API interactions described. The PR involves detailed documentation updates which include code examples for various operations using the Joomla framework and PHP cURL functions. Reviewing this PR would require a thorough understanding of Joomla's web services, API endpoint behavior, and the correctness of the provided examples.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The documentation should ensure that examples provided are fully operational and correctly demonstrate the API usage. Any error in these examples could lead to improper API use.

    Security Concern: The documentation mentions storing API tokens securely but does not provide detailed guidance on implementing secure storage practices in the examples.

    🔒 Security concerns

    No specific security vulnerabilities are introduced in the documentation itself, but it is crucial to ensure that the examples provided advocate for best security practices, especially regarding the handling of API tokens and secure HTTP requests.

    Copy link
    Contributor

    qodo-merge-pro bot commented Jun 4, 2024

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add the missing data payload to the curl command for creating a banner

    The curl command for creating a banner is missing the actual data payload. This can lead
    to confusion for users trying to follow the documentation.

    docs/general-concepts/webservices/webservices-core-endpoints.md [24]

    -curl -X POST -H "Content-Type: application/json" /api/index.php/v1/banners -d
    +curl -X POST -H "Content-Type: application/json" /api/index.php/v1/banners -d '{"catid": 3, "clicks": 0, "custombannercode": "", "description": "Text", "metakey": "", "name": "Name", "params": {"alt": "", "height": "", "imageurl": "", "width": ""}}'
     
    Suggestion importance[1-10]: 10

    Why: The suggestion correctly identifies and resolves a significant issue where the curl command for creating a banner is missing its data payload, which is crucial for correct API usage and documentation clarity.

    10
    Add the missing data payload to the curl command for creating a client

    The curl command for creating a client is missing the actual data payload. This can lead
    to confusion for users trying to follow the documentation.

    docs/general-concepts/webservices/webservices-core-endpoints.md [73]

    -curl -X POST -H "Content-Type: application/json" /api/index.php/v1/banners/clients -d
    +curl -X POST -H "Content-Type: application/json" /api/index.php/v1/banners/clients -d '{"contact": "Name", "email": "[email protected]", "extrainfo": "", "metakey": "", "name": "Clients", "state": 1}'
     
    Suggestion importance[1-10]: 10

    Why: The suggestion accurately addresses the issue where the curl command for creating a client is missing its data payload. This addition is essential for proper API documentation and usage.

    10
    Add the missing data payload to the curl command for creating a contact

    The curl command for creating a contact is missing the actual data payload. This can lead
    to confusion for users trying to follow the documentation.

    docs/general-concepts/webservices/webservices-core-endpoints.md [200]

    -curl -X POST -H "Content-Type: application/json" /api/index.php/v1/contacts -d
    +curl -X POST -H "Content-Type: application/json" /api/index.php/v1/contacts -d '{"alias": "contact", "catid": 4, "language": "*", "name": "Contact"}'
     
    Suggestion importance[1-10]: 10

    Why: This suggestion correctly identifies a critical issue where the curl command for creating a contact lacks the necessary data payload. Adding this information significantly improves the documentation's accuracy and utility.

    10
    Best practice
    Add error handling for cURL execution to help in debugging issues

    To handle potential errors during the cURL execution, it's a good practice to check for
    errors using curl_errno and curl_error functions. This will help in debugging issues
    related to cURL requests.

    docs/general-concepts/webservices/using-external-php.md [65-67]

     $response = curl_exec($curl);
    +if (curl_errno($curl)) {
    +    echo 'cURL error: ' . curl_error($curl);
    +} else {
    +    echo $response;
    +}
     curl_close($curl);
    -echo $response;
     
    Suggestion importance[1-10]: 8

    Why: Adding error handling for cURL operations is crucial for identifying issues during API interactions, which improves the robustness of the code.

    8
    Add error handling for HTTP request execution to manage response status codes

    To handle potential errors during the HTTP request execution, it's a good practice to
    check the response status code and handle errors accordingly.

    docs/general-concepts/webservices/using-joomla-framework.md [64]

    -echo $response->body;
    +if ($response->code >= 200 && $response->code < 300) {
    +    echo $response->body;
    +} else {
    +    echo 'HTTP error: ' . $response->code;
    +}
     
    Suggestion importance[1-10]: 8

    Why: Proper error handling based on HTTP response status codes is essential for correctly managing API responses and errors.

    8
    Security
    Add a check to ensure the API token is set before making the cURL request

    To improve security, ensure that the $token variable is not left empty. You can add a
    check to validate that the token is set before making the cURL request.

    docs/general-concepts/webservices/using-external-php.md [22]

     $token = '';
    +if (empty($token)) {
    +    die('API token is required.');
    +}
     
    Suggestion importance[1-10]: 7

    Why: Ensuring that the API token is set before making requests is a critical security practice to prevent unauthorized access.

    7
    Add a check to ensure the API token is set before making the HTTP request

    To improve security, ensure that the $token variable is not left empty. You can add a
    check to validate that the token is set before making the HTTP request.

    docs/general-concepts/webservices/using-joomla-framework.md [26]

     $token = '';
    +if (empty($token)) {
    +    die('API token is required.');
    +}
     
    Suggestion importance[1-10]: 7

    Why: Checking if the API token is set before making HTTP requests is a fundamental security measure to avoid unauthorized operations.

    7

    @HLeithner
    Copy link
    Member

    @pe7er CI failed, because I think something needs to be escaped

    @pe7er
    Copy link
    Collaborator Author

    pe7er commented Jun 4, 2024

    Thanks @HLeithner !
    I've escaped or replaced some quotes. I'll try to restart drone.

    @HLeithner
    Copy link
    Member

    @pe7er still not success full, you can do this on your local machine too. just run npm run build

    @pe7er
    Copy link
    Collaborator Author

    pe7er commented Jun 4, 2024

    Thanks! I am currently trying the installation process from README.md

    @pe7er
    Copy link
    Collaborator Author

    pe7er commented Jun 4, 2024

    I've solved some issues locally but I don't know how to solve the following with parts like:

    curl -X GET /api/index.php/v1/content/articles/{article_id}

    The error message complains:ReferenceError: article_id is not defined

    How to escape the {article_id} within that bash part?
    Or should we replace the curly brackets of the placeholder with some other characters?

    @HLeithner
    Copy link
    Member

    @pe7er fixed the issue but did you looked at #82 ? I think that's a much better way for documenting the api endpoints, it's also useful for code generators and IDEs

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation Review effort [1-5]: 4
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants