Rest Api on several DB (Oracle, MySql and PostGreSql)

mirko
Member | 13
+
0
-

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
+
+6
-

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.

There is also prepared full-function example project based on Apitte + Nettrine (Doctrine) + Contributte libraries called Forest Skeleton.

mirko
Member | 13
+
+1
-

Thanks a lot for your answer Felix.
I'm going to study it and looking for a tutorial step by step.
Have a nice evening.
Bye Mirko

mirko
Member | 13
+
0
-

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
+
+1
-

It should be composer create-project planette/forest-project --stability=dev as there is no release tag.

mirko
Member | 13
+
0
-

Solved!
The correct command is:

composer create-project -s dev planette/forest-project acme

Cross your fingers and stay with me :)
Thanks for support
Hi every body
Mirko

mirko
Member | 13
+
0
-

It works!
But return this message:
{"status":"error","message":"Client authentication failed","code":401}
I return to study this situation.
I'll keep in touch.
Bye everybody
Mirko

Last edited by mirko (2019-12-25 20:57)

Marek Bartoš
Nette Blogger | 1263
+
+1
-

It's AuthenticationMiddleware. access_token=admin in url query should work
https://github.com/…ddleware.php#…
https://github.com/…nticator.php#…

mirko
Member | 13
+
0
-

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)

mirko
Member | 13
+
0
-

Tracy should be active
Why I don't see the debugger bar?
I set debug enable!
I don't understand…

Damned :(
Ideas?

I'm going mad…
Mirko

Marek Bartoš
Nette Blogger | 1263
+
+1
-

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
+
0
-

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
+
+1
-

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
+
0
-

@Mabar I'm going to follow your advice
thanks forever :)
Mirko

Last edited by mirko (2019-12-26 11:08)

mirko
Member | 13
+
0
-

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
+
+1
-

Never really used, but you may try thephpleague/oauth2-server which has middlewares compatible with out apitte/middlewares
https://github.com/…c/Middleware

mirko
Member | 13
+
0
-

@Mabar thanks again
Mirko