I posted about this a while ago but nobody responded and now I'm trying to give it another go.
https://laracasts.com/discuss/channels/testing/api-testing-in-travis-ci
Integration API testing with Travis-CI and Laravel HTTP issue
For some reason when I hit the endpoint of the API it always returns 404. There's some other tests in the Laravel AngularJS framework I'm using that work fine but they are just hitting basic routes such as;
public function testServeAngular()
{
$this->visit('/')
->see('ng-app');
}
public function testUnsupportedBrowserPage()
{
$this->visit('/unsupported-browser')
->see('update your browser')
->see('Internet Explorer');
}
These 2 tests work fine by the way.
I have tried running a web server as mentioned in another post I found on the forum but this does not work either.
https://laracasts.com/discuss/channels/testing/testing-api-calls-on-travis
I am using the Dingo API library on Laravel 5.1 for this project. It's also worth pointing out that all of my tests work locally.
Related
My app required an app server and api/search calls. It all works fine when the app is installed in our own shopware test shops.
But as the app is ready now I made an test environment in our shopware account. Installation including registration with our app server went fine. But all the api calls failed. The reason seems to be that I do not get an access token. The call for the access token gives me an 302 Found error.
But the code is ok as all works in our test shops, prod and dev.
So, what could be the problem in the sw account test environment?
I found the problem! The shop url I got during registration was
"https://....sw.testenvironment.de/shop/public".
Api calls didn't work with this url.
But I changed it to
"https://....sw.testenvironment.de/shop/public/".
It worked.
The shopware test environment seems to have a problem with the /.
In our own shopware test shops it worked fine without the / at the end.
I've spent a few hours looking for a reliable httpClient for my Symfony3.4 (php 7.2) project. I need to get data from an external API endpoint. I tried:
symfony/http-client (didn't work since it's created for symfony 4.3 and higher)
guzzle/http-client (didn't work, because I received an error that GuzzleHttp\Client service doesn't exist)
php-http/httplug-bundle (didn't work as well due to "Unexpected exception when instantiating class.")
Maybe someone could suggest a reliable and working library for making api requests?
In our Symfony 3.4 project, we use the kriswallsmith/buzz bundle to perform HTTP requests.
i'm creating spa with vuejs 2 using laravel passport with the same tutorial like in laracast and there is something weird happening, i first using this api route for my api calls from vue using axios
Route::middleware('auth:api')->get('/get_artikel', 'ArtikelController#get_artikel');
and it works fine. But when i change it to this
Route::resource('artikel', 'ArtikelController');
and add __construct into ArtikelController for auth
public function __construct()
{
$this->middleware('auth');
}
its return 401 unathorized, even thought when i open inspector in chrome and in application tab i see laravel_token, laravel_session and XSRF-TOKEN in there.
so what is happening here? i do some searching and everybody say it works fine in ngix server and there is no working solution for apache server (i have tried all of it)
for the auth, passport and everything else i follow laravel documentation.
We are currently trying to start writing WebApi services for our products switching from traditional WCF SOAP based services. The challenge we have got is how to provide the api documentation. I came across the SwaggerUi/swash buckle.
One limitation we have is we do not want to host the WebApi services in IIS but in a Windows Service. I am new to Web Api so I might be doing things the wrong way.
So for testing, I am hosting the web api in a console application. I can use the HttpClient to invoke the Get method on the Web Api but I can't access the same if I type the url in a web browser (is this normal for self hosted web api?).
So I installed the Swashbuckle.core nuget package and included the following code in the Startup class (Owin selfhosted).
var config = new HttpConfiguration();
config
.EnableSwagger(c =>
{
c.IncludeXmlComments(GetXmlCommentsPath());
c.SingleApiVersion("v1", "WebApi");
c.ResolveConflictingActions(x => x.First());
})
.EnableSwaggerUi();
private static string GetXmlCommentsPath()
{
var path = $#"{AppDomain.CurrentDomain.BaseDirectory}\WebApiHost.XML";
return path;
}
When I browse to the following location
http://localhost:5000/swagger/ui/index
I get "page cannot be displayed" in IE. Similar for chrome.
Is there anything special that needs to be done when hosting a WebApi in a console/windows service application to get the documentation automatically?
(I have enabled Xml documentation for the project)
I have now attached a test project. Please follow the link below:
Test project
Regards,
Nas
Your problem is not with Swashbuckle, which is configured correctly. Instead it is with the fact that your OWin web app has closed by the time the browser navigates to the swagger URI. Your using statement means that the web app is shut down at the end of it - well before Chrome has opened and navigated to the swagger path. You need to ensure the web app is still running - then your path will be valid (although in your source code you have different ports 9000 and 5000 in your url variables).
I'm new to ASP.NET Web API and I'm struggling with a very strange problem.
I have some code which calls a RESTful service and it executes fine from a console project, but I can't get it to run from an MVC4 project running under .NET 4.0
The code to call the service is very simple:
internal string Test()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://testserver");
var task = client.GetAsync("/someUri")
var response = task.Result;
response.EnsureSuccessStatusCode();
return response.Content.ReadAsStringAsync().Result;
}
}
As mentioned, called from a console project it works as expected and I get a response in milliseconds, however if I call the method from an action in my MVC4 controller after a few seconds I get a message stating that:
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to repond".
Weirdly, when debugging the MVC4 version, the task status always shows as WaitingForActivation.
Running fiddler doesn't show any request being made from the MVC4 version, but again does for the Console version.
After a fairly serious bit of googling I can't find anyone else who seems to have had this problem, so I'm guessing that I've fundamentally misunderstood something, but at the moment I'm not sure what!
Updated 16:55 BST, 11/09/2012
To make things even weirder, I've just created a new MVC4 site and I can call the method without any problems! I'm now trying to compare the sites, however one was an existing site that was upgraded to MVC4 and the other is a new blank site, so spotting the relevant difference could be tricky.
Updated 16:44 BST, 14/09/2012
This is now looking like some infrastructure / networking issue.
I upgraded the project to VS2012 with .NET 4.5 so that I could use async/await to try the suggested implementations to avoid a deadlock. This didn't change anything so I went back to square 1.
I created a new solution with a new MVC4 project, a new services library and a unit test project to run the service library outside of MVC.
In the service library I created one method to call a public "what's my IP" service, and another to call a company service that's exposed publicly but only responds properly to company IP addresses.
For some background, I connect in to the company LAN via a VPN.
When disconnected from the VPN, in both unit tests and MVC, the IP service responds HTTP 200, the company service responds HTTP 404 as expected.
When connected to the VPN, unit tests both respond HTTP 200, MVC both timeout.
Next I ran MS Soap Tool locally and used that to proxy calls to the company services. All calls (whether from unit tests or MVC) show a request and response, but the unit test registers the response whilst the MVC controller does not.
My only other thought is that it could be something to do with the size of the reply? All the "successes" have very small replies other than the unit test calling the company service?
The Microsoft recommended way to upgrade an MVC3 to MVC4 site is to start with a completely new MVC4 site a migrate your views, controllers & code over. So I think that your upgrade steps may be part of your issue, since you were able to get it to work in the new MVC4 site you created. If you need to manually upgrade your existing site, I would follow the steps outlined in Upgrading ASP.NET MVC 3 Project to ASP.NET MVC 4