Postman random data for each run of a request - postman

Currently using postman to build up a few collections for api calls to our custom API. I'm using the faker library which is built in and in the body of a request I am using for example:
"profile": {
"firstName": "{{$randomFirstName}}",
"lastName": "{{$randomLastName}}",
"email": "{{$randomEmail}}",
"login": "{{$randomEmail}}"
}
What I am expecting to happen is that new data is put in with each request ie:
run 1 : "firstname" : "adam"
run 2 : "firstname" : "peter"
but im not seeing this. Each time its the same:
run 1 : "firstname" : "adam"
run 2 : "firstname" : "adam"
Any idea why im not getting new fake data each time?

Related

Ember DS.hasMany children not showing up with JSON API

I am trying to use the JSON API Adapter with ember-cli 2.5.1 , but I'm having a bit of trouble.
I have a todo-list.js model, which has a "hasMany" relationship to todo-list-item.js. Getting the todo-list, the server returns this:
{
"links": {
"self": "http://localhost:4200/service/v1/todolists/b-tlst-af69786c-cbaf-4df9-a4a3-d8232677006a"
},
"data": {
"type": "todo-list",
"id": "b-tlst-af69786c-cbaf-4df9-a4a3-d8232677006a",
"attributes": {
"name": "b1-TodoList",
"created-on": 1468474962458,
"modified-on": 1468474962458
},
"relationships": {
"todolistitems": {
"data": {
"type": "todo-list-item",
"id": "b-todo-b5e3c146-d93a-4f97-8540-875bbcd156ca"
}
}
}
}
}
If there had been two TodoListItem children instead of one, the value of that "data" key would have been an array, rather than an object.
After receiving this, I was expecting the Ember Chrome plug-in's "Data" tab to show 1 TodoList and 1 child TodoListItem. Instead, it shows 1 TodoList and 0 TodoListItems.
I note from the Network tab that the browser never makes a request to get the items listed in the "data" section of the response.
Is the relationships section above correct and sufficient?
It turns out to have been caused by promise misunderstandings on the client side, and additionally, on the server I had to put dashes in the "relationships" key (i.e. "todo-list-items") and make the value of "data" an array.

Recommended pattern to implement global Search with multiple Objects type (Ember 2 + JSONAPI)

I am new to Ember and I will like to implement a server side search endpoint that returns results for several models/tables in DB.
Trying to figure out what is the best practice to do this in Ember.
Server results can contain several types of objects/models, each model is already defined in ember-data.
So far I am able to retrieve the results (I can see the results in ember-inspector) but I am not able to render it properly (I only have access to first object for some reason).
Current architecture:
rails-5 server with JSONAPI response
ember 2.3 with multiple models
Flow:
POST /search with body:
{"search":{"query": "xxx","size": "10"}}
RESULT:
{
"data": [
{
"id": "111111",
"type": "foo",
"attributes": {
"x": "y"
}
},
{
"id": "222222",
"type": "bar",
"attributes": {
"z": "y"
}
}
]
}

Ember API response returns token in meta data. How to retrieve this meta token value using ember data?

I've model called "customer" which returns personal details of customer in below structure. It also returns token in meta data. How to retrieve this from model?
"customer" : {
"title" : "Mr",
"firstName": "Person",
"surname" : "surname",
"primaryTelephoneNumber" : {
"number" : "0123456789",
"type": "Home"
}
},
"meta" : {
"token" : "6e16063a-8a89-5d1a-b9cb-72d14c4c7579"
}
To get the metadata just use the metadataFor method, so in your case it would be var meta = this.store.metadataFor("customer");

Design history tracking database using django-rest-framework

I am using the django-rest-framework api for the first time. Here's my question:
I need to design a database in which there are two tables:
Server => To save the server information such as ip address and server name
id: INT, name: VARCHAR, ip_address: VARCHAR
Deploy => The deploys on the server including the deploy date and a comment message
id: INT, server_id: FK to Server, deploy_date: DATETIME, message: VARCHAR
I am asked to keep track of the deploy information and design the following APIs:
get /servers/ => get all the server information with the latest deploy on that server
Example:
[
{
"id" : 1,
"name" : "qa-001",
"ip_address" : "192.168.1.1",
"deploy" :
{
"id" : 1,
"deploy_date" : "2013-09-09 12:00:00",
"message" : "test new api"
}
},
{
"id" : 2,
"name" : "qa-002",
"ip_address" : "192.168.1.2",
"deploy" :
{
"id" : 2,
"deploy_date" : "2013-09-10 12:00:00",
"message" : "test second message"
}
}
]
get /deploys/ => get all the deploy information
Example:
[
{
"id" : 1,
"deploy_date" : "2013-09-09 12:00:00",
"message" : "test new api",
"server_id" : 1
},
{
"id" : 2,
"deploy_date" : "2013-09-10 12:00:00",
"message" : "test second message",
"server_id" : 2
},
{
"id" : 3,
"deploy_date" : "2013-09-08 12:00:00",
"message" : "test new api",
"server_id" : 1
}
]
// Deploy 3 does not show up in the get servers return json
// because deploy 1 was deployed on the same server but later than deploy 3.
POST /deploys/ => To insert a new deploy
POST /servers/ => To insert a new server
...
I have played around with django-rest-framework tutorial code and read about different api documentations but couldn't figure out how to implement the features that I list above.
Please let me know if you have any ideas on how to implement this or if you think another database design would fit this requirement more.
Thanks!
Found this question which is very similar to mine.
How can I apply a filter to a nested resource in Django REST framework?
And I solved my problem by using the SerializerMethodField

How to query JSON file in emberjs

I´ve never work with JSON before, but have with xml, php, mysql. I have a populated database on the server and would like to develop a web application with ember.js to interact with this data (CRUD).
Where should I start? I know ember-data has most of the things I would need when developing, but I'm unsure of how to start.
Since the database holds different tables, is it possible to keep this information in one json file? is it the appropriate way to do it? How do I automatically produce this json file from the server?
you can start with a read query :
You upload a file sample with the json syntaxe on your server (or use your json service if it's enable) to start quickly. Test that you can access to it in your browser, for example :
[ {"id": 1, "desc": "hmarchadour"}, {"id": 2, "desc": "moderator"} ]
Well now you take/create a view in your embjer js and you can use JQuery to call this file/service :
Ember.View.create({
templateName : "templateName" // you
stuff : [],
didInsertElement : function() {
$.ajax({
type : "GET",
url : <url-of-your-sample>,
dataType: "json",
success : function(result) {
var tmpStuff = json2Stuff(result);
this.set('stuff', tmpStuff);
},
error : ... }
);
}
});
Regards,