-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add rest api basics #486
Conversation
Done:
Todo:
|
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="/js/swagger-ui-bundle-4.5.0.js" crossorigin></script> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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']); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
So I am done with the main implementation as far as I see. I will refactor the |
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