restful-url

When do I use path params vs. query params in a RESTful API?

给你一囗甜甜゛ 提交于 2019-11-28 02:48:52
I want to make my RESTful API very predictable. What is the best practice for deciding when to make a segmentation of data using the URI rather than by using query params. It makes sense to me that system parameters that support pagination, sorting, and grouping be after the '?' But what about fields like 'status' and 'region' or other attributes that segment your collection? If those are to be query params as well, what is the rule of thumb on knowing when to use path params? Best practice for RESTful API design is that path params are used to identify a specific resource or resources, while

How to access the services from RESTful API in my angularjs page?

試著忘記壹切 提交于 2019-11-27 16:40:26
I am very new to angularJS. I am searching for accessing services from RESTful API, but I didn't get any idea. How can I do that? Option 1: $http service AngularJS provides the $http service that does exactly what you want: Sending AJAX requests to web services and receiving data from them, using JSON (which is perfectly for talking to REST services). To give an example (taken from the AngularJS documentation and slightly adapted): $http({ method: 'GET', url: '/foo' }). success(function (data, status, headers, config) { // ... }). error(function (data, status, headers, config) { // ... });

Passing array in GET for a REST call

那年仲夏 提交于 2019-11-27 12:39:07
问题 I have a url to fetch appointments for a user like this: /user/:userId/appointments How should the url look like if I want to get appointments for multiple users? should it be: /appointments?users=1d1,1d2.. Thanks, Chris. 回答1: Collections are a resource so /appointments is fine as the resource. Collections also typically offer filters via the querystring which is essentially what users=id1,id2... is. So, /appointments?users=id1,id2 is fine as a filtered RESTful resource. 回答2: I think it's a

Confusion Between Noun vs. Verb in Rest URLs

戏子无情 提交于 2019-11-27 09:41:31
问题 I have studied over the internet about restful APIs that it focuses on nouns not verbs in the url pattern, but now I am seeing multiple links that use verbs in the URL. Here is an example. POST /v1/payments/authorization/<Authorization-Id>/capture POST /v1/payments/authorization/<Authorization-Id>/void POST /v1/payments/authorization/<Authorization-Id>/reauthorize this is Paypal apis. PayPal API also on wikipedia on HTATEOAS page they gave a example ; <?xml version="1.0"?> <account> <account

Hyphen, underscore, or camelCase as word delimiter in URIs?

自作多情 提交于 2019-11-27 08:54:58
问题 I'm designing an HTTP-based API for an intranet app. I realize it's a pretty small concern in the grand scheme of things, but: should I use hyphens, underscores, or camelCase to delimit words in the URIs? Here are my initial thoughts: camelCase possible issues if server is case-insensitive seems to have fairly widespread use in query string keys (http://api.example.com? searchQuery =...), but not in other URI parts Hyphen more aesthetically pleasing than the other alternatives seems to be

How to handle hierarchical routes in ASP.NET Web API?

寵の児 提交于 2019-11-27 05:05:42
问题 Currently I have two controllers 1 - Parent Controller 2 - Child Controller I access my Parent Controller like this someurl\parentcontroller Now I want to access my children controller like this someurl\parentcontroller\1\childcontroller This last url should return all the children of a particular parent. I have this route currently in my global.asax file routes.MapHttpRoute ("Route1", "{controller}/{id}", new { id = RouteParameter.Optional }); I am not sure how can I achieve my parent\id

Spring MVC Controller: Redirect without parameters being added to my url

寵の児 提交于 2019-11-27 04:02:22
I'm trying to redirect without parameters being added to my URL. @Controller ... public class SomeController { ... @RequestMapping("save/") public String doSave(...) { ... return "redirect:/success/"; } @RequestMapping("success/") public String doSuccess(...) { ... return "success"; } After a redirect my url looks always something like this: .../success/?param1=xxx&param2=xxx . Since I want my URLs to be kind of RESTful and I never need the params after a redirect, I don't want them to be added on a redirect. Any ideas how to get rid of them? In Spring 3.1 use option

What’s the best RESTful method to return total number of items in an object?

…衆ロ難τιáo~ 提交于 2019-11-27 02:31:21
I’m developing a REST API service for a large social networking website I’m involved in. So far, it’s working great. I can issue GET , POST , PUT and DELETE requests to object URLs and affect my data. However, this data is paged (limited to 30 results at a time). However, what would be the best RESTful way to get the total number of say, members, via my API? Currently, I issue requests to a URL structure like the following: /api/members —Returns a list of members (30 at a time as mentioned above) /api/members/1 —Affects a single member, depending on request method used My question is: how

Is using magic (me/self) resource identifiers going against REST principles?

旧城冷巷雨未停 提交于 2019-11-27 01:22:10
问题 I've seen URIs that support magic ids for the authenticated user like below: GET /user/me - list my profile GET /user/me/photos - list my photos where the ones below use the actual user id GET /user/742924 GET /user/742924/photos The problem I see is that the same resource id points to a different resource depending on the authenticated user. Is this going against any REST principles? 回答1: Using /me to name a resource that corresponds to the authenticated user is perfectly fine from a REST

Jersey with Struts2 [duplicate]

房东的猫 提交于 2019-11-26 19:11:44
This question already has an answer here: Request is going to Struts Dispatcher 2 answers I am using jersey with Struts2. But by RestFul Service calls are not working. Below are my configurations files struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> </result-types> <interceptors>