I want to perform a rest request with sencha ext js. Threfore I created a model and a store with a proxy. Then I invoked the load function of the store. The problem is that after the invocation the store is still empty. I know this because I debugged it. This is the code:
var myModel = Ext.create('Ext.data.Model', {
fields: [
{ name: 'name' },
{ name: 'age' }
]
});
var myStore = Ext.create('Ext.data.Store', {
model: myModel,
proxy: {
type: 'rest',
url: 'http://localhost:8080/blablabla',
}
});
myStore.load();
The url 'http://localhost:8080/blablabla' is correct because when I type it in the browser I get the json list of users with the "name" and "age" fields. So the server works.
Here is an example of json that I should get:
[ {
"id" : 1,
"name" : "john",
"age": 40
}, {
"id" : 2,
"name" : "jack",
"age": 30
} ]
My Sencha code was correct. The problem was CORS not enabled. So I resolved by adding #CrossOrigin above my server method.
#CrossOrigin
#RequestMapping
public List<Thing> getThings() {
...
return myListOfThings;
}
#CrossOrigin did the trick.
Related
I am trying to add a single line item with modifiers using the Rest API. I see answers that it's not possible while adding bulk line items (the documentation for both suggests that this should be possible).
This is the request I am sending.
URL: https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items
Request Type: POST
"item": {
"id":"9S1MXGERPQ7ER"
}
"modifications" : [{
"modifier" : {
"id" : "ZM8MV5X3M7R72",
"modifierGroup": {
"id" : "YC351CMAHF6AY"
}
},
"modifier" : {
"id" : "0X5A869PQT858",
"modifierGroup": {
"id" : "XZP32FHXQWKE6"
}
}
}]
The item gets created fine. but none of the modifiers are added.
I checked that creating a line item initially and then making an explicit call to the below URL to add modification works fine, but with this approach we can only add 1 modifier per call.
https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items/LINEITEMID/modifications
Request:
{
"modifier" : {
"id" : "ZM8MV5X3M7R72"
}
}
With this approach we have to make multiple calls per line item based on number of modifiers selected.
Am I missing something here?
I have the same problem. you are missing the name and amount property of the modifier. These are required fields e.g
URL: https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items
Request Type: POST
"item": {
"id":"9S1MXGERPQ7ER"
}
"modifications" : [{
"modifier" : {
"id" : "ZM8MV5X3M7R72",
"modifierGroup": {
"id" : "YC351CMAHF6AY"
},
},
"name": "yourModifierName",
"amount": "amountOfModifier"
}]
I have two types: Todo and Comment.
type Todo {
id: ID!
name: String
description: String
priority: Int
status: TodoStatus
comments: [Comment]
}
type Comment {
todoid: ID!
commentid: String!
content: String
}
Then I have a Query getTodo but the thing is I want to include a content arg that filters the comment (child) if the string passed is in the content of Comment.
getTodo(id: ID!, content: String!): Todo
I have tried attaching a resolver to comments (under Todo). If I add a filter here, how will I be able to get the ctx.args.content which was passed in getTodo(id: ID!, content: String!).
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "todoid = :id",
"expressionValues" : {
":id" : {
"S" : "${ctx.args.id}"
}
}
},
"filter": {
"expression": "contains(content, :content)",
"expressionValues" : {
":content": {
"S": "${ctx.args.content}"
}
}
}
}
Or if I remove this filter and leave it like this:
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "todoid = :id",
"expressionValues" : {
":id" : {
"S" : "${ctx.args.id}"
}
}
}
}
How will I modify getTodo Resolver to fetch comments (with content that contains the string passed)?
Can I do it like this (accessing if comments.content contains the content string args passed):
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "id = :id",
"expressionValues" : {
":id" : {
"S" : "${ctx.args.id}"
}
}
},
"filter": {
"expression": "contains(comments.content, :content)",
"expressionValues" : {
":content": {
"S": "${ctx.args.content}"
}
}
}
}
The GraphQL arguments you are accessing via $ctx.args are available at the field level. So when you access them when resolving the Post.comments field, you get back all the arguments on that field and that field only.
So to get the content string argument you could update your Todo type to:
type Todo {
id: ID!
name: String
description: String
priority: Int
status: TodoStatus
comments(content: String): [Comment]
}
Another way, if you don't want to expose the content argument on the Post.comments field and keep the argument on the Query.getTodo field, you could pass the arguments via the source. In your Query.getTodo resolver you could return the content field as part of the todo result. You would then be able to access it inside the Todo.comments resolver via $ctx.source.content.
I'm working with two microservices using Spring Cloud Contract. One providing its contract, and the other one consuming it. In one scenario the provider response is the same that the request.
So the provider contract is like this:
Contract.make {
request {
method 'POST'
url '/provider/foo'
body(
"foo": $(regex("[a-zA-Z0-9]{20}"))
)
}
response {
status 200
body(
"fooResponse": fromRequest().body("\$.foo")
)
}
And the generated wiremock mapping:
{
"id" : "a80c0871-f4c0-49e3-8cc1-94de39899669",
"request" : {
"url" : "/provider/foo",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(#.['foo'] =~ /[a-zA-Z0-9]{20}/)]"
} ]
},
"response" : {
"status" : 200,
"body" : "{\"fooResponse\":\"{{{jsonpath this '$.foo'}}}\"}",
"transformers" : [ "response-template" ]
},
"uuid" : "a80c0871-f4c0-49e3-8cc1-94de39899669",
"scenarioName" : "scenarioReturnSameAsRequest",
"requiredScenarioState" : "Started"
}
But when my code calls to the provider, with foo as any text, the wiremock returns:
{
"fooResponse" : "{{{jsonpath this '$.foo'}}}"
}
How can I build a contract that responses the same parameters as the request body?
Edit
I tried with a fixed value on the response and works fine:
Contract.make {
request {
method 'POST'
url '/provider/foo'
body(
"foo": $(regex("[a-zA-Z0-9]{20}"))
)
}
response {
status 200
body(
"fooResponse": "fooValue"
)
}
Now wiremock return:
{
"fooResponse" : "fooValue"
}
Maybe is not supported getting from request a regex value?
I think the mapping should contain request.body instead of this. Also I wonder if you need to use 3 times a { or just 2 times. Or do you need to escape these?
Possible mapping:
"response" : {
"status" : 200,
"body" : "{\"fooResponse\":\"{{jsonpath request.body '$.foo'}}\"}",
"transformers" : [ "response-template" ]
},
See also the chapter JSONPath helper on http://wiremock.org/docs/response-templating
I had the same problem once. You can try to use value() like this:
"fooResponse": value(fromRequest().body('$.foo'))
I've been using Rest-DSL (Camel v2.18.1) and trying to set up my own RestOperationResponseMsgDefinition so as to have a useful API doc. By setting a class to the responseModel to tell which object will be returned in case of success, its structure is properly shown in the API doc. However, if I create a class that has that object within, all endpoints which mention it as their outputType/responseModel stop showing the correct structure in the API doc and put "string" instead. Like this:
My outputType/responseModel:
class Address {
private Integer id;
private String descr;
}
API-doc snippet:
"/addresses" : {
"get" : {
"produces" : [ "application/json" ],
"responses" : {
"200" : {
"description" : "Success.",
"schema" : {
"$ref" : "#/definitions/Address"
}
}
...
In Swagger-UI, the response example value is shown as:
{
"id": "string",
"descr": "string"
}
Everything is alright till I create any class having an Address object within! For instance:
class Store {
private Integer id;
private String name;
private Address address;
}
Now, for the same endpoint mentioned before, I get...
"/addresses" : {
"get" : {
"produces" : [ "application/json" ],
"responses" : {
"200" : {
"description" : "Success.",
"schema" : {
"type" : "string",
"format" : "com.mycompany.integration.domain.Address"
}
}
...
And the following in Swagger-UI as example value:
"string"
Has anybody ever passed through and solved this? This seems a bug, though...
I have problem with REST API(s) for front-end GUI and am wondering which approach is better. Are there any design patterns for these types of problems?
uri: /users/list
response: [
{
id: "1",
name "Aaa",
surname "Bbb",
contactDetails: {
telephone: "111-111-111"
email: "mail#mail.pl"
}
},
...
]
OR
uri: /users/list
response: [
{
id: "1",
name "Aaa",
surname "Bbb"
},
...
]
uri: /emails/list?userIds=1,..
response: [
{
userId: "1",
email: "mail#mail.pl"
}
]
uri: /telephones/list?userIds=1,..
response: [
{
userId: "1",
telephone: "111-111-111"
}
]
and it's the same for a single user:
uri : users/{id}
uri : users/{id}/emails
uri : users/{id}/telephones
============== Extended class model =================================
Below I paste JSON classes designed for question needs.
SystemPart : {
id : "sp2",
name : "UserAdministration",
parentSystemPart : {
id : "sp1",
name : "Administration",
...
}
...
}
SystemPermission : {
permissionType : "MODERATOR",
systemParts : [ // list of SystemPart
{
id : "sp1",
name : "UserAdministration",
parentSystemPart:{...}
},
...
],
...
}
User: {
id : "u1",
name : "a",
surname : "b",
contactDetails : {
telephone : "111-111-111"
email : "mail#mail.com"
},
identityCard : {
idType : "Id",
number : "321"
}
systemPermissions : [ // list of SystemPermission
{
permissionType : "MODERATOR",
systemParts : [...]
},
...
]
}
MapPoint : {
id : "mp1",
x : 11.11,
y : 22.22,
createdBy : { // User
id : "u1",
...
systemPermission : [...]
}
}
GUI client would like to show map point data with only it's author name, and surname
and now api for list of MapPoints
/map-points/list?x=11.00&y=22.00&d=5.0
other part of GUI would like to get list of users with its permissions
/users/list?page=0&size=5
In my opinion problem is in map-points list api which JSON is to big
I'd go with the first approach. The User class is pretty small and I don't see any benefits to calling the service separately for contact details.
Ensure that the client can filter the results based on every parameter, that way it is easy for the user of your API to get exactly what he/she wants.
For e.g. /users/list will get back everything which is perfect if there are relatively small number of users in the list and it's better to eagerly cache them all to improve client's performance.
uri: /users/list
response: [
{
id: "1",
name "Aaa",
surname "Bbb",
contactDetails: {
telephone: "111-111-111"
email: "mail#mail.pl"
}
},
...
]
If the number of users are significantly large, make sure the list can be filtered down to a small quantity based on every(or at least the significant ones like last name) parameter and the client can call your service for specific users and lazily load them as and when needed.
uri: /users/list?surname=Bbb
or
uri: /users/list?id=1
should get back:
response: [
{
id: "1",
name "Aaa",
surname "Bbb",
contactDetails: {
telephone: "111-111-111"
email: "mail#mail.pl"
}
}
]