Home > Blockchain >  Create web API with /path/to/{unique-path}/ design
Create web API with /path/to/{unique-path}/ design

Time:10-11

I am currently learning web development and working on my own small website. I followed a tutorial by W3Schools and used the learned to create a working login page. It takes the input and sends it using JQuery.

Now I wanted to learn more about how to create an API to manage users and found a guide on the best practices when designing a REST Api by Microsoft. It also contained an example of what a user and order management API system could look like. In the article they show a similar table looking like this:

Resource POST GET PUT DELETE
/users Create user Get all users Bulk update users Delete all users
/users/{id} Error Get user Info Update user details Delete user
/users/{id}/orders Create order Get all orders Bulk update orders Remove all orders
/users/{id}/orders/{id} Error Get Order Info Update order details Delete order

How can I implement this into my project and is it possible with just PHP and Javascript?
When searching for it online I only found C# answers

My request for logging in currently looks like this:

function login() {
    var username = $("#username-input").val();
    var password = $("#password-input").val();
    $.post("/ajax/account/login.php", 
        {
            username: username,
            password: password
        },
        function (data, status, jqXHR) {
            console.log(jqXHR.responseText)
            data = JSON.parse(get_ajax_response_text(jqXHR))
            if(data.hasOwnProperty("error")) {
                showError("<b>ERROR:</b> "   data["message"]);
            } else {
                setTimeout(function() {
                    window.location.href = "/hub";
                }, 1000)
                showSuccess(data["message"]);
            }
        },
    );
}

Thanks for helping in Advance

CodePudding user response:

I found this article which should help me to keep building my page:
https://code.tutsplus.com/tutorials/how-to-build-a-simple-rest-api-in-php--cms-37000

I didn't exactly know what to search for, so I will keep this question open for others to find.

  • Related