how to debug during API with laravel - laravel

I run my laravel app #localhost.
```php artisan serve --host=localhostIP```
On top I run an Andoid app with the same base URL.
Could anyone tell me how can I debug incoming API´s calls
like if BASEURL/users is called?
Furthermore, how can I log the happening events in the console

I am developing API's with laravel too, i do it this way:
composer require laravel/homestead to have it all in a vm 😉 see https://laravel.com/docs/master/homestead for more information, i use the "per project" installation
Download postman to have the best tool for sending querys to your api and to test your api quick -> https://www.getpostman.com (i use it free)
configure and run your homestead (it's not that complicated).
your homestead is fit with php and xdebug enabled
i am using phpStorm and have my vagrant setup as deployment target
"listen to debug" with phpstorm
to your GET requests, add a queryparam XDEBUG_SESSION_START=PHPSTORM
i can debug my api now 😉
i also wrote https://logcrawler.de to receive the log informations of all my api's and all my server 🤩
I hope, i could help you a little bit

This is my way, but I think it's not good!
Create router api in config/web, Eg:
router/api: Route::post('/check_api', [CheckController::class, 'testFunc'])->name('api.check_api');
web/api: Route::post('test/check_api', [CheckController::class, 'testFunc'])->name('test.check_api');
Create a post by form or ajax in one resource/view like index
Go to page, and debug with phpstorm

You can use logging feature of Laravel. Apply Logs on entry point of application to test whether API url is hitting or not.

use postman
https://www.getpostman.com/downloads/
it's an excellent thing very much usefull

Related

Edge dev tools for VS Code gives "ERR_UNSAFE_REDIRECT" error during authentication, possibly from the "file:///" url scheme - is there a workaround?

I am currently using the latest stable VS Code version on Windows 10 (ver 20H2, build 19042.1826) with the Edge Dev Tools VS Code extension. The application I'm currently developing is just a static site using Vue.js, not using a Node.js server to run and debug. The Edge tools work great, right out of the box. I started up the app by opening the root "index.html" file, and clicked "Run and Debug" per the documentation.
The app starts up, I can hit breakpoints, etc. all good. However, this app uses a 3rd party service to authenticate and authorize users (from ArcGIS Online) and it seems the "file:///C:/path/to/root/index.html" url is not allowed to be redirected back to from the authentication service page.
My Google-fu is failing me here and I can't seem to figure out how this would work. Has anyone experienced such an issue before? Is it possible to use a "http://localhost" url on some port here instead?
The authentication service disallows setting a redirect url which has a "file:///" scheme.
In order to avoid exposing users to open redirector attacks, developers must register one or more redirect URLs for the application. The authorization server must never redirect to any other location. You can try adding a redirect URI according to this doc.
IMO, file:/// scheme may not work, so I suggest you use a http://localhost url since only http and https are mentioned in the doc.
To resolve this issue, I followed the guidance in yu-zhou's comments above. My solution was to use the Live Server VS Code extension to host and run the app locally. I set the "NoBrowser" setting in Live Server to "true" so that a new browser instance would not be launched on Live Server startup. I then configured launch.json as follows:
{
"name": "Edge: Debug app",
"request": "launch",
"type": "msedge",
"url": "http://localhost:5500/my-app/index.html",
"runtimeArgs": ["--disable-web-security"],
"skipFiles": ["<node_internals>/**", "**/*.com*/**"]
}

Postman not Working with Laravel Valet (Local)

When I use Postman to send or get data to/from my local Laravel applications it always returns the error...
Could not get any response.
For example, a GET request to
http://demo_app.localhost/api/data.
I use Laravel Valet on my Mac. It looks like Postman can't find the local domain.
I had the same issue when trying to use valet with Postman and what fixed it for me was turning off the SSL verification in Settings > General. I believe valet is using some internal SSL certificate by default that cannot be verified properly by Postman.
Use TLD .test, if your Valet version is up-to-date and not specifically configured to use .localhost.
Should be like http://demo_app.test/api/data
See official docs for background:
Valet documentation at chapter "Using Another Domain".
I had the same issue and used all the suggestion above, none of them works.
For my case, I used the following command to fix the problem:
php artisan optimize
This clears the cache and config files and reloads the new api Routes added to the Laravel framework.

Want to implement web sockets in Laravel

I want to implement web notifications in Laravel using web sockets. I have
tried pusher. It is very easy but it is a paid package. I have also tried redis and socket.io for which I have to install horizon. I am running Windows and I cannot install it on Windows according to what I have read about horizon.
So I am very confused about push notification. I am trying for at least one week but haven't found any solution yet. My front end is in angluar 5/android and backend is in Laravel 5.6.
Can you please suggest me any good ideas to implement push notification?
You have been use pusher,so I assume you know how to use event.
I recommend you laravel-echo-server.It's very easy to use,with a built-in api.
Here is a fresh example of a laravel-echo project from scratch.
After you set up the project.
you will need predis if you haven't install it yet
composer require predis/predis
redis-server /usr/local/etc/redis.conf
run npm install -g laravel-echo-server
run laravel-echo-server init
uncomment App\Providers\BroadcastServiceProvider::class in config/app.php
add <script src="https://cdn.jsdelivr.net/npm/socket.io-client#2.1.1/dist/socket.io.js"></script> in your app.blade.php
you need a socketio-client ,you can run npm install --save laravel-echo .In case you are not familiar with npm or vue, you can simply include this compiled file from my github project.compiledjs
add this to app.blade.php
<script>
window.Echo = new Echo({
broadcaster: 'socket.io',
host: '{{url('/').':6001'}}',
});
Echo.private(`App.User.{{Auth::id()}}`) // private channel
.listen('NewMessage', (e) => {
console.log(e)
});
</script>
finally run laravel-echo-server start and open you project ,you will see
[20:53:21] - Lv5OKDAcuSLsK1nBAAAE authenticated for: private-
App.User.1
[20:53:21] - Lv5OKDAcuSLsK1nBAAAE joined channel: private-App.User.1
you can listen any event you want or other notifications
here is my github project echo-example
add a little code so that you can use postman send message to specfic user.You can see the message from chrome console.You can get more details from github project screenshots
Take a look at this article. It covers implementing websocket in laravel using redis driver, Laravel echo and socket.io client.
According to above article:
“Why don’t you just use Pusher?”
Here is the thing.
Laravel comes with Pusher enabled. Even though Pusher seems like a quick “Plug and play” solution (which it is), it comes with limitations. Check https://pusher.com/pricing
And most of the tutorials trick you with their title of implementing Websockets when in reality they just want to give you Pusher. (And my favorite part is when they say that you can easily switch to socket.io)
As per laravel documentation, I will recommend using Pusher. I have created a package for to user WebSockets in laravel.
https://www.techzonemind.com/scalable-websocket-server-laravel-applications/
It will use Redis for background queuing to optimize performance. I have used it in few solutions. I may not be usable in all use cases. But good to have a look.
PHP not build to execute concurrent tasks, if you have a choice, nodejs will be a better solution,
THE BEST WAY TO INTEGRATE REALTIME IN LARAVEL IS NIETHER NODE NOR PUSHER
You find Pusher Easier and you don't want to pay the price . Then without hesitation you should try Laravel Websockets . Its a very simple Pusher Replacement .
In Short You use the pusher client libs to access a pusher like server that is hosted in your php server . Since its open source its free .
Its better than using socket.io or redis because they require you to pay additional
server costs .
You can check their demo app here
PS
If you want more custom controls then you can use ratchet

Hyperledger-Composer REST Authentication

Request assistance with hyperledger composer. I have created a network and web app around the REST API that was built with the composer-rest-server. I am able to add participants, assets and execute transaction with the default settings. I am now trying to add authentication to the REST server as well as add identities to new participants. However I got stuck. I have reviewed the information at
https://hyperledger.github.io/composer/integrating/enabling-rest-authentication.html
But I'm not sure where I should place the export COMPOSER_PROVIDERS='{.... information to continue the setup.
Any assistance, tips and tricks are much appreciated.
Ok so I figured it out. The problem was that I was running off an older version of composer-rest-server.
I installed the developer tool back in Sep 17 and did the tutorial soon after. I tried the tutorial again and noticed that the deployment command was different and it would not let me deploy my network.
So I updated the composer-rest-server and component cli and it deployed fine. I then followed the steps on the authentication webpage that I referenced above and it worked as intended. I deployed my personal network with the new command and it worked as intended.
Lesson learned this stuff is still being updated and I should be more aware on what changes. Thank you very much #nilakantha singh deo
Open a new terminal from inside the project folder.Format your COMPOSER_PROVIDERS in notepad according to the document you mentioned and copy the whole message and paste it in the terminal.Then you can echo it (see it) by typing the following.
echo $COMPOSER_PROVIDERS
It should ideally return the same json file.
Then make sure that the compopser-rest-server is running with multiuser mode and authentication enabled in the same terminal where you echoed and saw the COMPOSER_PROVIDERS.
In browser now type
localhost:3000/auth/github
It should ask for authentication .Rest of the steps are listed in the document you mentioned.
Cheers!

Error 404 for rest webservice request in offline app in GeneXus Ev3 U9

I'm developing an offline Android app with Genexus Ev3 U9 and when I try the app in the device I see there is no initial synchronization, even when I try to execute a manual sync the app shuts down. The cat log shows that request made to URLs like http://192.168.12.17/MyAppSmartDevicesEnvironment/gxmetadata/MyApp.android.json
worked fine but when the app tries to get this URL http://192.168.12.17/MyAppSmartDevicesEnvironment/rest/MyAppOfflineDatabase?fmt=json&event=gxchecksync returns 404 I tried the same link in my laptop and it's like the requested resource was not created by GeneXus.
What could be wrong?
There are actually a couple of things you might want to check.
When you accessed http://192.168.12.17/MyAppSmartDevicesEnvironment/gxmetadata/MyApp.android.json you got data but that just means that the virtual directory was successfully created. (which is good of course)
Then you need to check if the WCF module is installed correctly, in order to do that you could try to go to http://192.168.12.17/MyAppSmartDevicesEnvironment/MyAppOfflineDatabase.svc/rest or any other service in your KB. That goes straight to the service implementation. (you can check you web.config file in order to see the actual rewriting rules)
If that works it's certainly a URL Rewrite problem like Sandro and Guscarr suggested.
You can download and install the module from here: http://www.iis.net/downloads/microsoft/url-rewrite
Gcastano,
It seems that you're generating to .net, right?
If so, it could be some problem with iis rewrite module.
Anyway you might check gx software requirements...
It seems that REST services cannot be run on your IIS, as Sandro said, try installing URLRewrite.
Further info at http://wiki.genexus.com/commwiki/servlet/wiki?14575,Android%20-%20FAQ%20and%20Common%20Issues

Resources