Closed Mubeen142 closed 3 months ago
Thanks @Mubeen142 for the PR. I'll be AFK the whole week. Will check it on the weekend.
ok. a few comments to start this,
The main reason I built this API is to remotely create users and give them access to sites.
Yeah I already mentioned this in the todos
I have already written all the backend code required for the API. The API has a good structure and follows industry standards.
Please rephrase this, I don't quite understand what you mean.
With this PR I wanted to create the structure for the API. The first API will be under v1. Its quite easy to add new endpoints. You add the endpoint in routes/v1.php and then add the controller method that can be copied from the endpoints that already exists.
Because servers are based on projects. we want to manage projects rather than users. We don't want every user to be able to have an API key but we want every vito instance to be able to have API keys.
It's about maintainability. we want it simple and easy to maintain.
I don't see any tests in your PR.
With this PR I am laying down the foundation for the v1 API.
Current Endpoints:
This API uses the conventional HTTP standards, returns correct HTTP status codes and has a good structure. It is also nicely integrated within the code and uses the same workflow (Actions, Validation, Models, etc...)
The API also allows you to filter, sort and include data
Include, Filter, Sort and Date:
domain.com/api/v1/users?include=projects,servers,scripts
This will return users including all their projects, servers and scripts. You can keep passing additional relations.domain.com/api/v1/users?filter[role]=admin&filter[timezone]=europe
The filter method allows you to filter users based on given parameters.domain.com/api/v1/users?sort[created_at]=desc
Sort allows you to sort by a specific column. Supported operators are asc, desc and randomdomain.com/api/v1/users?date=30days
The date method allows you to filter users created between certain days. You can pass today, yesterday, 3-7-14-30-90days and custom dates using ?date=YYYY-MM-DD,YYY-MM-DDAnd ofcourse you can use filters, sorts, includes and date in combination. You can also pass an per_page parameter.
This logic is consistent throughout all API endpoints that return the full collection.
Creating API Keys
Users can create API keys on /settings/api-v1. I have not yet added the menu to the sidebar.
More Details
Other methods, such as creating, updating, deleting using the API go through Actions. Below is an example:
This ensures that validation errors are returned nicely, better error handling quicker workflow, and one codebase.
Left Todo