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

Add rest api basics #486

Merged
merged 11 commits into from
Sep 2, 2023
Merged

Add rest api basics #486

merged 11 commits into from
Sep 2, 2023

Conversation

leepeuker
Copy link
Owner

@leepeuker leepeuker commented Sep 2, 2023

You can try out the new swagger UI for openapi schema at for example http://127.0.0.1/docs/api

You can get the openapi schema as json from http://127.0.0.1/api/openapi.json

@leepeuker leepeuker requested a review from JVT038 September 2, 2023 10:46
@leepeuker
Copy link
Owner Author

leepeuker commented Sep 2, 2023

Done:

  • setup new /api namespace
  • added first api endpoint /api/users/{username}/history
  • added openai schema for the first endpoint
  • added swagger ui

Todo:

  • add api authentication and enforce it

@leepeuker leepeuker linked an issue Sep 2, 2023 that may be closed by this pull request
9 tasks
@leepeuker leepeuker linked an issue Sep 2, 2023 that may be closed by this pull request
</head>
<body>
<div id="swagger-ui"></div>
<script src="/js/swagger-ui-bundle-4.5.0.js" crossorigin></script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I mentioned before, it would be better to install swagger as an NPM package; maybe this is a good opportunity to do so?

Copy link
Owner Author

Choose a reason for hiding this comment

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

sadly no, I am glad I have time to implement this at all, the additional hours it would probably take to set npm up and configure everything is not in my budget

Comment on lines +142 to +146
function addApiRoutes(FastRoute\RouteCollector $routeCollector) : void
{
$routeCollector->addRoute('GET', '/openapi.json', [Api\OpenApiController::class, 'getSchema']);
$routeCollector->addRoute('GET', '/users/{username:[a-zA-Z0-9]+}/history', [Api\HistoryController::class, 'getHistory']);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're going to add authentication, try to do that by adding middleware in the routes here, instead of adding an if statement in every controller method in the ApiController.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I have not time to look into how to integrate a middleware here atm

@leepeuker
Copy link
Owner Author

So I am done with the main implementation as far as I see. I will refactor the HistoryController, especially the user authentication stuff, before merging this.

@leepeuker leepeuker marked this pull request as ready for review September 2, 2023 15:54
@leepeuker leepeuker merged commit 9b81c4e into main Sep 2, 2023
@leepeuker leepeuker deleted the add-rest-api-basics branch September 2, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a REST API for third party usage Document API endpoints
2 participants