I want to generate a unique SessionId every time when the user Login. I have read various articles and found the below line useful
var sessionId = OperationContext.Current.SessionId;
But still I am getting null in SessionId.
Please give me some useful way.
Related
When I look at the source of a profile page like https://<connections-host>/profiles/html/profileView.do?userid=98A10FD8-FCC3-5DD7-C125-6A9B0055D8C8 I see two kind of ids in the page source:
profilesData.displayedUser = {
key: "7a74e3bf-6cf4-40cd-a593-801275661353",
dn: "<dn>",
displayName: "Alice Someone",
userid:"98A10FD8-FCC3-5DD7-C125-6A9B0055D8C8",
// ...
};
userid seems like a regular GUID for the user, that's clear for me. But why do we have an additional key attribute? It also looks like another GUID but lowercase.
Connections API
The reason why I'm asking is: IBM's User API asks for a key attribute, e.g. /profiles/atom/profileEntry.do?key=7a74e3bf-6cf4-40cd-a593-801275661353. We can also call /profiles/atom/profileEntry.do?userid=98A10FD8-FCC3-5DD7-C125-6A9B0055D8C8, altough this is not official documentated.
Can someone explain why we have two ids? And what is the reason for using key instead of userid here? It disagrees the concept of an id to be unique.
Connections is built from several different apps with different databases (People, Blogs, Homepage, ....). Each DB has its own user table with their own keys. The second id is the userid, which should be the same across all DBs.
In your example, the key refers to the peopledb. It's only valid in the profiles app.
The Userid is valid accross all connections apps.
I have 2 tables, User table and User_token table, they are one to one/none relatonship, not sure how to create this RESTful API.
i prefer to setup
# to get user attributes
GET /users/123
# to get user's token
GET /users/123/token
or should i create
# to get user attributes and token by JOIN the table
GET /users/123
the argument we have here, if we are doing the first setup, which i like it, it takes thousands of API requests compare to second one
that is depend you requirement.
for example if you need User Attributes and Token every time than
# to get user attributes and token by JOIN the table
GET /users/123
is better.
other wise another approach is good to get required data when needed.
REST has nothing to do with your database structure.
Your resources can contain properties or sub-resources. Every resource has at least one resource identifier (URL).
So in your case the GET /users/123 is a valid solution.
Can anyone tell me if they are know for certain whether or not survey monkey's api has the ability to return the unique ID associated with their designated unique id specifications:
http://help.surveymonkey.com/articles/en_US/kb/Can-I-track-respondents-using-a-unique-ID
It states the following regarding viewing this in the aforementioned link:
When these results come back on the survey, that custom ID of "00001"
appears in the Custom Value field in the Analyze > Browse Responses
section.
However I cannot find any mention of this data being returned from their API in the API documentation:
https://developer.surveymonkey.com
It can be retrieved by sending 'custom_id' as a requested field to 'get_respondent_list':
https://developer.surveymonkey.com/mashery/get_respondent_list
It will then be in the 'custom_id' field in the respondent's dictionary.
My application is two parts :
an android app that lets the user creates comments on stuff. Each comment has a unique id (a string)
a server with a REST api (json based) that gathers the data. The server generates the unique id.
The android app creates a new comment by POSTing the comment data to the server, minus the unique id (it gets generated by the server upon the comment creation).
The unique id will be used in the subsequent requests (For example : <myserver>/api/v1/comment/<id>)
The question is after the POST, the server needs a way to tell the android app what the id of the newly created comment is.
What is the REST way to do get the new id ?
Note : I would like to avoid to create an extra call to get a new identifier and then to post my comment.
https://www.rfc-editor.org/rfc/rfc2616#section-10.2.2
You respond with a 201 Created status and a Location header containing the URI to the created resource.
just reply to the POST with the id
Scenario 1
In my web application say for there is a screen for adding an employee to system. As soon as user tabs after entering name of the employee, it generates the employee code automatically (which is the next field) based on some logic and already present records in the database.
Now I want to expose rest API for this application so that third party devs can build on top of it. So, I will have a resource called as /Employee which will respond for GET, PUT and DELETE verbs. But when a client needs to autofill the code, which is a GET operation, it will be on what resource? Should I make a new resource /EmployeeCodeFor/{Name} or I should get it on /Employee/{Name}/GenerateCode? If I go with /Employee/{Name}/GenerateCode then what about my resource to GET, PUT and DELETE for Employee i.e. actually /Employee/{Id}?
Scenario 2
Here lets take the case of a stackoverflow post. So lets say the resource would be /Post/{Id}. In the same way as in the previous example it lists me possible duplicate question as soon as I tab out of the Title field.
Again on what URL I should get those possible duplicates?
I can't think of more scenarios just now. But many such kind of scenarios may come up in real life application development. How to implement them in RESTful way?
Update on scenario 1
Code and Id are two different fields. Id is primary key, code can be duplicate across departments just to illustrate. Also to generate a code, name should be provided first. So, if user types a name "FirstName LastName" then server might generate FL003 as code assuming that there are already two more employees with firstname starting from F and lastname starting from L in the said department. Department can be identified based on the logged in user.
One way to allow the server an opportunity to pre-fill a bunch of elements in a new resource is to do
POST /Employees
{with empty body}
=>
201 Created
Location: http://example.org/employee/3443
<Employee Id="3443">
<Code>E1001</Code>
<FirstName></FirstName>
<LastName></LastName>
</Employee>
This gives the server one chance to provide default values. If you are looking for a more interactive way for the server to provide feedback during the input, I have another approach but it will take quite a bit more explaining.
Scenario 1
Let say your employee code is a unique identifier. In this case, to get it, you would allow the user to complete any field for the new employee and then make a POST. The server would generate the code and respond to the POST with a link to /Employee/{generated_code} which is the record for your newly created employee.
A GET on /Employee would return a list of all employees. A GET on /Employee/{a_code} will give you the employee detail.
Scenario 2
You could have some kind of query on the /Post collection like /Post?title_like={question_title}. A GET /Post?title_like=REST How to would return you a list of all questions containing "REST How to".