Rest Api on several DB (Oracle, MySql and PostGreSql)
- mirko
- Member | 13
Hi every body
I'm developing a new project; I have several DB (Oracle, MySql and PostGreSql)
and I must to develop an unique Rest Api.
Looking around I found https://github.com/drahak/Restful,
but latest commit is very old (10 May 2017).
It's an healthy project or there is a newest that work better?
I read this article https://forum.nette.org/…php-rest-api
but it's very old too.
Thanks in advance for your advices.
Best regards Mirko
- Felix
- Nette Core | 1197
Hi @mirko.
There is a newer alternative library you can use, it's called Apitte.
It's heavily based on annotations, controllers instead of presenters and supports PSR-7.
/**
* @Path("/hello")
*/
final class HelloController implements IController
{
/**
* @Path("/world")
* @Method("GET")
*/
public function index(ApiRequest $request, ApiResponse $response): ApiResponse
{
return $response->writeBody('Hello world!');
}
}
You can find many examples on Github, https://github.com/…e/playground.
- https://github.com/…te-fullstack
- https://github.com/…apitte-micro
- https://github.com/…nette-simple
- https://github.com/…pitte-simple
There is also prepared full-function example project based on Apitte + Nettrine (Doctrine) + Contributte libraries called Forest Skeleton.
- mirko
- Member | 13
First attemp don't have success. :(
I obtain this error:
C:\xampp\htdocs\forest>composer create-project planette/forest-project
[InvalidArgumentException]
Could not find package planette/forest-project with stability stable.
create-project -s [–prefer-source] [–prefer-dist] [–repository REPOSITORY] [–repository-url REPOSITORY-URL] [–dev] [–no-dev] [–no-custom-installers] [–no-scripts] [–no-progress] [–no-secure-http] [–keep-vcs] [–remove-vcs] [–no-install] [–ignore-platform-reqs] [–] [<package>] [<directory>] [<version>]
I'm continuing to search a solution
Bye everybody
Mirko
Last edited by mirko (2019-12-25 20:22)
- Marek Bartoš
- Nette Blogger | 1263
It should be
composer create-project planette/forest-project --stability=dev
as
there is no release tag.
- Marek Bartoš
- Nette Blogger | 1263
It's AuthenticationMiddleware. access_token=admin
in url query
should work
https://github.com/…ddleware.php#…
https://github.com/…nticator.php#…
- mirko
- Member | 13
Thanks a lot Mabar for your help; I type this URl http://localhost/…api/v1/users?…
and the response is: “Application encountered an internal error. Please try
again later.”
I have a Mysql table User:
-------------------------
Column Type
-------------------------
id int(6) unsigned Auto Increment
employee_id int(10) NULL
name varchar(255)
email varchar(255)
password varchar(255)
code varchar(32) NULL
status int(3) [1]
role int(3)
I changed the config file:
parameters:
database:
dsn: 'mysql:host=localhost;dbname=forest'
user: 'forest'
password: 'forest'
and worked on the user entity.
Anyone has some advisings for me?
Thanks Mirko
Last edited by mirko (2019-12-25 22:27)
- Marek Bartoš
- Nette Blogger | 1263
Tracy could be displayed only for requests with compatible content type
(html), api response is usually json. This is workarounded through
apitte/negotiation and apitte/debug (via .debug url suffix and
$response->withEntity()), but I guess they are not set up in
planette/forest-project.
Btw, did you try read the docs? It imho contains all necessary informations.
Last edited by Mabar (2019-12-25 22:43)
- mirko
- Member | 13
Hi Mabar
I'm reading the nette.org website and this github page: https://github.com/…rest-project.
In the .doc dir I found only 3 images, but no docuemntation.
I googled “nette php planete/forest-project documentation” and found this
2 resources.
If u can help me with somes link I appreciate very much.
Thanks for your help and your kindness.
I'm sorry but I'm very beginner with Nette.
Bye every body
Mirko
- Marek Bartoš
- Nette Blogger | 1263
I mean Apitte docs – at Contributte
website or github.
planette/forest-project is just an example, how you can integrate apitte into
nette/web-project.
I would start with nette/web-project and then look at apitte/core setup and
endpoints docs sections
- mirko
- Member | 13
Success !!!
Very thanks to @Mabar and his adivices, the api section is done.
Now it's work separately on every single db.
I'm working to integrate so I can get data from the different Db type
simultaneously.
Only the auth is missing; I'd like to implement OAuth2 login.
Anyone can suggest me a path? A guide? A tutorial? A lib?
Greeting every body
Mirko
- Marek Bartoš
- Nette Blogger | 1263
Never really used, but you may try thephpleague/oauth2-server which has
middlewares compatible with out apitte/middlewares
https://github.com/…c/Middleware