I am preparing a mock service where the request coming to mock server as:
http://localhost:8080/api/v01/transactions/307/events/
And hence I have configured the mock service resource path as: (And I am getting success response)
But the problem is the ID. I.e. 307. In the next/subsequent request it will come as 308,309, 100, 56 etc... which is dynamic.
My aim is can we configure the resource path as dynamic so that it whatever the ID comes, it will accept and return response?
Please advise !!!
Thanks,
Ashwin
Related
In our API, one of the endpoint will expect clients to provide body/payload only in certain scenario.
If the API is unable to generate a payload for given request based on the origin of the client then, we want our API to provide response with the right status code to the client, so that they know they have to provide additional information. Once the client fulfills the request with body/payload then the api will process the request as normal.
I just wanted to know is there any standard, predefined status code or procedure to implement this kind of endpoint in API design or do we have to just reject the request with some custom status code and then ask the client to implement a logic based on custom code?.
Thanks,
Vinoth
HTTP Status codes don't, nor are they intended to, map precisely against every real world error. They represent categories of error.
For example, a 404 means that the resource couldn't be found, but if your path is /customers/11/animals/5 then there are several things which could be wrong with the path. customer 11 may not have an animal 5 for example, or there may be no customer 11. There is no http response for "animal not found". Or your API may not have any calls with that pattern of URL to begin with.
You should return a status code which represents what "category" of error you have (in this case, something was not found), and the response body should contain more specific details about the error. To make things simpler, I find it helpful if the data structure is the same for a success and error (it makes parsing much easier) with a "data" field which varies per response.
Here is one example:
status code: 404 not found
body: {
"messageDetailCode" :"CustomerNotFound",
"messageDetail" : "Customer not found",
"data" : null
}
Further reading:
What's an appropriate HTTP status code to return by a REST API service for a validation failure?
I want to check whether my deployed ASP.NET application returns Healthy from health check endpoints or not.
Unfortunately, the success criteria samples of the "Invoke Rest API" release gate only show how to evaluate JSON responses like eq(root['status'], 'successful') or eq(count(jsonpath('Items[?(#.price<50)]')).
As my endpoint doesn't return any JSON I wonder if it's possible to do a simple stupid string equality check somehow?
Of course I could rely on checking the HTTP status code, I feel like it should be possible to access the response body.
This is the exception I get when using eq(root, "Healthy"):
If your endpoint returns just a string try simply this:
eq(root, 'SomeString')
This is really strange that you get such error. It works on my release pipeline:
Here is settings:
And here result:
Agree with Krzysztof Madej
Exception Message: Error parsing API response into a JSON object.
You could check the “URL suffix and parameters” field in “Invoke Rest API task”.
Please make sure that the whole URL is valid.
The whole URL contains the Server URL (Set in service connection) and the URL suffix and parameters (Set in Invoke Rest API task).
Hope this helps.
I would like to use Spring Cloud Contract (https://spring.io/projects/spring-cloud-contract) in order to test frontend to backend interactions: especially to catch such errors as 400 http errors.
I was able to run my stubs with the spring cloud contract stub runner. However I noticed that when the actual backend would return a 400, the running stubs return a 404 not found error.
Here is my contract:
description: |
Signup use case
```
given:
a user signs up
when:
the sign up request is valid
then:
the user is signed up
```
request:
method: POST
url: /api/signup
body:
userAccountType: PARENTS
email: john#example.com
firstName: John
plainPassword: secret
address:
placeId: 'an_id'
description: '10 Downing Street'
headers:
Content-Type: application/json
response:
status: 200
If my frontend (i.e. Angular) just issues a Http POST with, say the email field missing, then I expect the running stubs to return a 400.
I would be grateful if someone could share best practices or tips in order to better leverage Spring Cloud Contract for the purpose of frontend/backend tests.
Although I agree with what Marcin said in the comments...
If you get 404 that means that WireMock couldn't find a stub. That means that your request >was not matched with a WireMock stub.
You should create another contract [for each invalid request] with [a] missing field and >mark it with status code 400
... there might be a way to cheat a little bit with priority
You could create a low-priority contract for any request that hits the correct URL to returns 400. On its own, this means every call to that URL would return a 400.
Then create contracts that hit the right URL with the right parameters to return 200 and the expected response and set their priority to high. Since these contracts overlap, the priority ensures that the 200 gets returned and not the 400.
Any other URL will still return 404.
Disclaimer: I have not actually tried this out myself.
I want to pass some data within request body, but I'm using GET request, because I just want to modify this data and send it back.
I know that it is bad practice to use body with GET requests.
But what should I do with this situation if I want to build correct RESTful service?
P.S. I'm not changin any object on server.
I'm not putting any new object on server.
You want a POST. Something like
POST /hashes
{
"myInput": ...
}
The response would be the hashed value. There's no rule that the created resource must be retained by the server.
From the RFC:
The action performed by the POST method might not result in a
resource that can be identified by a URI. In this case, either 200
(OK) or 204 (No Content) is the appropriate response status,
depending on whether or not the response includes an entity that
describes the result.
In BizTalk 2006, I am trying to set up a messaging-only scenario whereby the recieved message (a string) is passed to a web service method that takes a single string parameter. In other words, the whole body of the BizTalk message should be passed as the parameter to the web service call.
The service method looks like this:
[WebMethod]
public void LogAuditEvent(string auditEventMessage)
I have set up the assembly with the proxy class in the SOAP adapter configuration as required, but I can't figure out how to get the message body to be passed as the parameter. Without doing anything special, I get the following error message:
Failed to serialize the message part
"auditEventMessage" into the type
"String" using namespace "".
I think this means that the adapter cannot find a message part named after the parameter. So, my question is what do I need to do to get my message set up correctly? I was thinking that maybe I needed to add an outbound map, but was not sure what to use as the source schema and how to generate a proper schema for the web service request message.
Does anyone have any pointers on this seemingly simple task?
Thanks.
TDL,
I would take a look at the links below for some tips on how to do this. SOAP adapter can be problematic I would recommend WCF if your using R2. And if not look at the WSE adapters as well.
http://blogs.digitaldeposit.net/saravana/post/2007/01/31/Calling-Web-Service-from-BizTalk-2006-in-a-Messaging-only-Scenario-(aka-Content-based-Routing).aspx
-and-
http://www.pluralsight.com/community/blogs/aaron/archive/2005/10/07/15386.aspx
-and-
http://social.technet.microsoft.com/Forums/en-US/biztalkgeneral/thread/92f2cad3-39b9-47d0-9e6f-011ccd2f9e10/
-Bryan