I´m trying to send a POST request that is an Person object that contains a list of contacts.
But I don´t know if this is the correct syntax to send a list:
{
"name":"romulo",
"contacts" : [
{
"contact" : "3466577"
},
{
"contact" : "532423"
}
]
}
But keeps me returning a 404 error
what i´m doing wrong?
post method:
#PostMapping("/person")
public void addPerson(#Valid #RequestBody Person person) {
Person savedPerson = personRepository.save(person);
List<Contact> contacts = person.getContacts();
for (Contact contact1 : contacts) {
contactRepository.save(contact1);
}
}
HTTP 404 is returned when the server is unable to find method to match your exact request.
For the mentioned request have the url as http://<context>/requestpath with request method as POST.(http://localhost:8080/person)
Check the request body and all the fields should exactly match the Person object else it may return HTPP 400.
In My Case it was simple mistake and spend an hour for figuring it out that i had space at the end of my url.
Related
I just created a proto file like this
service Customer {
rpc SubmitCustomer(SubmitCustomerRequest) returns (SubmitCustomerResponse) {}
}
message SubmitCustomerRequest {
string name = 1;
map<string, google.protobuf.Any> details = 2;
}
message SubmitCustomerResponse {
int64 id = 1;
}
The code itself works when I called this from the client. But, I'm having trouble with testing it directly from bloomrpc or postman.
{
"name": "great name",
"details": {
"some_details": "detail value",
"some_int": 123
}
}
it throws me this error when I tried to hit it
.packets.SubmitCustomerRequest.details: object expected
I think I'm aware that the problem is with the details syntax format when I hit it on postman, but I'm not sure what the correct format is supposed to be. I've tried modifying it with any other possible format and none works either.
rpc CreateBook(CreateBookRequest) returns (Book) {
option (google.api.http) = {
post: "/v1/{parent=publishers/*}/books"
body: "book"
};
}
message CreateBookRequest {
// The publisher who will publish this book.
// When using HTTP/JSON, this field is automatically populated based
// on the URI, because of the `{parent=publishers/*}` syntax.
string parent = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = {
child_type: "library.googleapis.com/Book"
}];
Book book = 2 [(google.api.field_behavior) = REQUIRED];
string book_id = 3;
}
I don't understand post: "/v1/{parent=publishers/*}/books"
I thought publishers was a field in CreateBookRequest, then it populates to http, so it is something like this
post: "/v1/parent=publishers_field_value/books"
But publishers is not a field in CreateBookRequest
No, publishers is part of the expected value of the parent field. So suppose you have a protobuf request like this:
{
"parent": "publishers/pub1",
"book_id": "xyz"
"book": {
"author": "Stacy"
}
}
That can be transcoded by a client into an HTTP request with:
Method: POST
URI: /v1/publishers/pub1/books?bookId=xyz (with the appropriate host name)
Body:
{
"author": "Stacy"
}
If you try to specify a request with a parent that doesn't match publishers/*, I'd expect transcoding to fail.
That's in terms of transcoding from protobuf to HTTP, in the request. (That's the direction I'm most familiar with, having been coding it in C# just this week...)
In the server, it should just be the opposite - so given the HTTP request above, the server should come up with the original protobuf request including parent="publishers/pub1".
For a lot more information on all of this, see the proto defining HttpRule.
I get a problem with the validation of a new user request on my api.
I know there's a problem in my code but I cannot figure it out :
UserType
postUserAction
And I send via google Postman, this json :
{
"username":"Username",
"email":"example#mail.com",
"plainPassword":"SecretPassword",
"lastname":"Smith",
"firstname":"John",
"job_position":"CEO",
"phone":"+666133742",
"company_name":"Microtosh",
"website":"www.omgthatsaflippingspider.com",
"sector":"Food & Stuff",
"address":"12 st Overkill",
"city":"SinCity",
"zip_code":"W4224",
"country":"US",
"billing_infos_same_as_company":true,
"putf":"1",
"das":"Manchester United"
}
Now I seems to validate but I get an error :
Column 'password' cannot be null
When I look up the $form -- before $userManager->updateUser($user) -- I get this :
plainPassword:
{
-children:
{
-first:
{
-errors:
[
"fos_user.password.mismatch"
]
}
second: [ ]
}
}
Now first, why does it validate since it didn't find a match between password and confirmation ?
And am I doing the right thing, with the creation of a new user ? I don't understand what I am missing.
Just change the form type of password field to password instead of repeated and it should work ;)
We are using WebApi v2.1 and validating ModelState via a filter applied in the WebApiConfig class.
Fields specified as required are not listed on the error message when we run on the server (Win Server 2008R2), but they work perfectly when we run locally (on IISExpress).
The request is correctly rejected locally and on the server, but the server response does not show the missing fields.
For Example:
Given a Local request that lacks the required abbreviation and issuerName fields, the response shows as expected:
{
"message": "The request is invalid.",
"modelState": {
"value": [
"Required property 'abbreviation' not found in JSON. Path '', line 18, position 2.",
"Required property 'issuerName' not found in JSON. Path '', line 18, position 2."
]
}
When the same request is sent to the server, the response shows:
{
"message": "The request is invalid.",
"modelState": {
"value": [
"An error has occurred.",
"An error has occurred."
]
}
}
Our filter is the following:
public class ValidateModelStateAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (!actionContext.ModelState.IsValid)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState);
}
}
}
Our data model class is decorated with the DataContract attribute, and the required fields are attributed like so:
[DataMember(IsRequired=true)]
public string IssuerName
The server is more restrictive about sending errors down ot the client. Try setting the IncludeErrorDetails flag on your httpconfiguration to verify that this is the underlying issue.
In general though turning this flag on is not the best idea, and you will want to serialize the errors down differently.
For more info:
http://blogs.msdn.com/b/youssefm/archive/2012/06/28/error-handling-in-asp-net-webapi.aspx
Inserting An entry to CalenderList returns "404 not found".
the request is as follows:
POST https://www.googleapis.com/calendar/v3/users/me/calendarList
Request Body:
{
"summary":"test Calender",
"id":"test#google.com",
"defaultReminders":[
{
"minutes":2,
"method":"email"
}
]
}
The response doesn't have any good explanation on the Error. Just the "Not Found".
What may have went wrong?