Let's say we have a website with user entities. If we follow the general standards for Rest API we would get some of the following urls:
GET /users : View list of users
GET /users/{id} : View specific user
POST /users : Add a new user to list
PUT /users/{id} : Update specific user
I have a page that is a form for creating a new user. To follow Rest API standards, what should the url be for getting this form? Would /users/add be appropriate?
I know the ideal thing would be to have this form as a pop-up modal on the list of users page. But, let's say that's not an option. We must pick a url for getting this page that contains a form for adding a user.
I can't say there's a strict rule about this. I think you can choose the name you want and on my own I did it like you're proposing: /users/add, just make sure you are using the same structure for other entities in your project, e.g. /products/add - in terms of consistency.
As the answer above, there is no universal rule for it. I tend to make my post urls like this /user/addNew
Related
I currently developed a solution for custom uploading videos for specific customers.
One of my customers need the ability to specify "interests" for a video he upload.
From the API documentation, interests are:
interests
list
One or more IDs of pages to target fans of pages.Use type of page to get possible IDs as find Targeting Options and use the returned id to specify.
There is some mis-documentation regarding this feature: "find Targeting Options" does not talks about type=page.
But, still, I can search for page, using the "search" endpoint: /2.5/search?q=gsw&type=page and get the ID of the page.
As to my understanding, I can specify a page, for example "Golden State Warriors" fan page, specify its id, and then every user which follows this page will be considered as interested in my post.
So, I think my flow should be:
1) Search for the requested page using the "search" api. Get the page's IDS.
2) When creating the video, specify the ID in the "interests" parameter list.
Now, I need to know how to specify the ID in the interests list - The documentation says it list, but the page ID as a number string...
So in conclusion, I would like some help in verifying that all that I have written is correct and make sense, and also to know how to get the int32 id of a page - is it just mistake in the documentaion?
Thanks!
Our app uses the Google Analytics Rest API. We'd like to get the number of page views generated by different links to the site.
For example, one link to our site might be:
http://oursite.com?linknum=12345
and another might be:
http://oursite.com?linknum=23456
We'd like to track the number of page views by all visitors who click on each link, so we need a way to filter by parameter.
So far, we just get the number of page views for all visitors without any filters:
curl 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:(our id) &metrics=ga:pageviews&start-date=2014-4-26&end-date=2011-12-08&access_token=(our access token)'
The best way to learn the API is to use the query explorer at
http://ga-dev-tools.appspot.com/explorer/
For your analysis, add dimension=ga:pagePath and sort=ga:pageviews.
In addition, you could ask for pages which match a filter expression.
For example filter=ga:pagePath=#linknum to only include pages with linknum.
My client want to published some adwords advertisement on Google. The website only purpose is presenting info about it's company and it's not an e-commerce site. Since adwords final result depend on conversion we decided to add simple form including following fields.
1) Name:
2) Email Address:
3) Occupation:
However, we need to display this form if only a person clicks on the 10% discount adword advertisement via Search or Display network. We think by user submitting this form user may contact us is definite.
My Questions are:
1) Is there a way to display this discount form only if user click the Google add? if so could you pls clarify
2) Is there a module for Drupal 7 to create custom form fields?
3) Otherwise is there a different method to achieve what I explained above?
The Referer HTTP header field might tell you the URL of the page from which the user might have come to your site.
The first might means, there is no quarantee that it is present.
The second might means, if it is present, there is no quarantee that it is accurate.
The Fields module can be used to create custom form fields. It is part of the Drupal 7 core. It can be used to attach fields to bundles. A bundle is a set of entities. EXamples are
The nodes of a node type are a bundle
All users are a bundle
The terms of a vocabulary are a bundle
The Fields module provides an API to define new entity types and groups them into bundles.
1 - You can create a unique Webform and exclude it from search engines in your robots.txt file. This will allow it to be accessed directly via the URL, but it won't be picked up by any search engine, and therefor can't be found by anonymous users. You'll have to add it in the robots file as such:
User-agent: *Disallow: /your-page-path/
You may also have to exclude it from your site's search (if you have it).
2 - If you haven't already tried the Webform module, it's a great module for creating custom forms and gathering submissions right within the Drupal site.
When I GET from http://example.com/organization/ I get a list of organizations.
When I GET from http://example.com/organization/xyz/ I get the record for the organization xyz.
When I POST form data to http://example.com/organization/ I create a new organization.
What URL should I use to GET a form to fill out to create a new organization via a POST to http://example.com/organization/?
Looking at How to do a RESTful request for an edit form? and other sources, it would seem that I am really looking for a form resource for organizations -- so I should GET that form at something like http://example.com/organization/form/ and POST to http://example.com/organization/ as described above. This seems...untidy though.
Update
tuespetre's comments have me thinking the best way to do this is to have a form resource. The organziation form is provided via a GET to /form/organization/ which is filled out and posted to /organization/.
A form in the sense that you speak of one is not a resource, but a template to gather user input to POST a new resource.
One really 'RESTful way' to do it would be to utilize some Javascript to 'include' that form in the collection page /organizations, either as a hidden 'slide-down' form or maybe a modal dialog that appears when a certain call to action button is pressed. This would make semantic sense for two reasons:
You won't have to have some arbitrary URI being used for the form (which is not really a resource in the sense that your domain objects are), and
the 'create' form is for POSTing to the collection, so it really closely relates to that collection and thus would not be at all out of place to have right there with the collection.
Of course, you will find many opinions on this, but I would rather not have arbitrary URIs that break the established pattern (i.e., you're not getting an organization with an id of 'new', so why have that inconsistency?)
If you're trying to implement it, I've seen it done in different ways and I don't think there's a rule (but there are different patterns/approachs that you could follow or not).
I would make it http://example.com/organization/new/
I'm a relative MVC noob coming from WebForms. I think I have a pretty good grasp of MVC with a couple exceptions, and I think I may have broken the pattern. I'm gonna try to keep this short, so I'm assuming that most of what I am asking is relatively obvious.
Let's say I have a news site with articles. In that case, a URL in the form of mynewssite.com/Articles/123 works just great because I don't care who views which article. The user can change the ArticleID in the URL to whatever they want and pull up that article. In my case, however, I only want the user to be able to view/edit data entities (articles, or whatever) that belong to them. To achieve this, I am using their UserID (GUID) as a foreign key in the database, and displaying a list of their data for them to choose from. Here comes the problem... when they click on the link that is created by Url.Action("Edit", New With {.id = item.id}) (I'm not using ActionLink because I need to add HTML content inside the link), the id shows up as a querystring parameter. I could add a route for it, but the id would still show up in the URL for them to tamper with. The obvious implication is that by tampering with the URL, they could view/edit any entity that they want.
What am I missing?
Is there a good way to pass the parameters without adding them on the URL? I know that I could put them in a form on the page and submit the form, but that seems cumbersome for my example, and I'm using jQuery.ajax in places that seems to conflict with this idea.
I could also check their UserID against the data in the Edit method, but that also seems cumbersome, too.
Is this question too broad? Please let me know what specifics you need. Thanks.
Even in Winforms, you would have to add special logic on each request to filter only the articles that the user owns. I don't see why MVC should be any different. Sure, you can use web.config to deny access to given url's, but not when you use a single page that takes a parameter of what data to show.
Your best bet is probably to filter this at the database level. By adding a where clause that includes the user id, then the app will return a "no records found" sort of error, and you can do whatever you want with it.
You could use forms authentication. This way when the user authenticates an encrypted cookie will be emitted which will contain his username which cannot be tampered with. Then you could verify whether the currently connected user has authorizations to edit this article.