I want to get reverse geocode of Here map to fetch user postalCode with specified Country. So, if user is not in that Country, it should give error/warning message.
How about enabling the parameter show->countryInfo on the request so that we receive the country info in the response, and then do your own client-side checking for that country? https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html
I need an API for getting country, state, city.
I need to get by following endpoints
/somepath - for countries
/:countryName - for states
/:stateName - for cities.
If you know any up to date API for this task, please write a comment about it.
Thanks
I'm trying to integrate the klarna api:
https://developers.klarna.com/en/us/kco-v3/checkout/javascript-api
Unfortunately when I do:
window._klarnaCheckout(function(api) {
api.on({
'change': function(data) {
console.log(data);
}
});
});
This only returns the zip and postal_code but not the entered email address or other information like the name.
Is this a klarna issue or am I missing something?
Only once the form within the Klarna iframe is submitted, the event is triggered, and information is returned. Unfortunately, I have only managed to get it to return email, postal_code, country, given_name and family_name. Address doesn't seem to want to play.
Hope this helps (at least a little).
First of all I am really not very familiar with the REST practice, and I am not very confident about the title of my question.
So I am trying to built a RESTful API using Laravel for a phonebook application. The phonebook may contain telephones of either employees (i.e real persons) or offices. For that reason I have three models
a Directorate with id and name fields,
an Employee with id and name fields and
a Telephone with id, tel, employee_id, directorate_id, description and type fields.
Telephones corresponding to a directorate's office have only the id, tel, directorate_id and description fields set, while the telephones corresponding to a person (i.e an employee) have set only the id, tel, employee_id, directorate_id, and type fields. That is how I separate them: a telephone having a description can only be an office's telephone, while a telephone having both the employee_id and the type_id set is an employee's telephone.
The models are related as follows:
an employee may have many telephones
a directorate, may have many telephones
class Directorate extends Model
{
public function telephones()
{
return $this->hasMany(Telephone::class);
}
public function employees()
{
return $this->hasMany(Employee::class);
}
}
class Employee extends Model
{
public function telephones()
{
return $this->hasMany(Telephone::class);
}
public function directorate()
{
return $this->belongTo(Directorate::class);
}
}
class Telephone extends Model
{
public function employee()
{
return $this->belongsTo(Employee::class);
}
}
My question is what should I a consider as my resource.
So far I am thinking of the following approach:
I shall use the concept of contact as resource. A contact may be the joined information of either an employee and a telephone, or a directorate and a telephone. For instance, a "contact" may contain the name of an employee with his related telephone numbers and telephone types, or it can contain the name of a directorate with the description of the telephone and the telephone number.
The "problem" with this approach is that I have ended up with (let's put it this way) two different types of resource: the employee's contacts and the directorate office's contacts, which contain slightly different information and thus, I need also to have different create and edit forms to interact with these two "types" of resources.
In order to implement the REST API, I am thinking of two different scenarios:
Use two different RESTful controllers, one EmployeeContacts and another OfficesContacts for separating conceptually the resource to an employee's and an office's resource, and accessing them through different URIs like:
example.com/phonebook/employees/{id}/edit
example.com/phonebook/offices/{id}/edit
example.com/phonebook/employees/create
etc...
Use a single RESTful controller, e.g. PhonebookContacts to access the resources through the same URIs as one resource (i.e. both employee's and office's contact resources now are considered to be just a "contact" resource)
//this refers to a contact resource that can be either an office's or a n employee's contact
example.com/phonebook/contact/{id}/edit
//this should list all resources (both employees and offices contacts)
example.com/phonebook/contact/
and then use conditional statements in the controller's create/store/edit/update methods to deal with them separately (e.g if an http POST request contains a description_id then it is an office contact and do this, or else if has an employee_id then it is an employee's contact so do that...)
I would like to hear your views, what of these two different scenarios do you consider to be better in the context of REST for my phonebook app? Would be better to think of a single "contact" resource and handle it using conditional statements with different return in the controller, or shall I separate the concept of "contact" to "employee's contact" and "office's contact" and use separate controllers and URI's to handle them?
Is there another approach that I could follow instead?
The way I would do it is with 2 different controllers for the simple reason of speed and responsiveness. Loading all contacts and filtering isn't as quick as loading the one part only.
However, you can always set in your controller the same return with different data. Such as EmployeeController#index returns view('contacts.index', compact('employeeContacts')), and OfficesController#index returns view('contacts.index', compact('officesContacts'))
EDIT:
Sorry, I have misread it...I thought you wanted to do the filtering in the view. Anyway, my practice is to do it separately, simply because the code is cleaner. If you want to make the whole REST more readable, you can put both resources in a group like so: Route::group(['prefix' => 'contact'], function(){ //routes here// });
So now you will have routes like:
example.com/contact/employees/
example.com/contact/offices/
I am not familiar at all with Laravel but since this question is about REST concepts (I have a small background on these) I should give it a try.
Since you are building a RESTful application, you must not consider others as human beings but only as machines. IMO the urls should determine the action that will be performed. Thus, by using different urls for different actions (perform a CRUD on a contact - either an Employee or a Directorate or SomethingElseInTheFuture) sounds good to me and fits the REST nice.
Hope this clarify the things for you!
[EDIT]
I believe jannis is right. It should be the verbs (GET, POST, PUT, PATCH etc) that make the action instead of the URLs. The urls are just respresenting the resources. My mistake. So both of your points of view are correct. It's just how convenient each approach is for your project (for now and for the near future of your project). IMO, I see #1 (two different restful controllers) more approchable.
Cheers and sorry for any misconception!
Given that I have a model denoting a city which holds a collection of streets.
public class City {
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<Street> Streets { get; }
}
public class Street {
public int Id { get; }
public string Name { get; }
public IEnumerable<Building> Buildings { get; }
}
If a client is interested in all cities (api/cities/all) and I'd return him the full collection, this would lead to a massive response, depending on the size of the dataset. So I thought first about returning only street ids inside the streets collection. This however feels awkward because while the ids might be useful to further fetch the streets, they hold no meaningful value for a client (it doesn't make sense to populate a list of ids on a view in order to show what streets are in a city, doesn't it?).
My next idea was to ditch the streets collection completely and instead offer an API endpoint to fetch the streets of a city:
api/cities/3737/streets
That way I can fetch a complete list of streets, however the returned data then doesn't contain any information to where the streets belong to. If I a client now wants to show both the streets and the city, he'd have to make 2 API calls to get the information he needs.
What is a common way to return such data?
I would create 2 city objects, a city object containing only the basic data(like ID & Name) and a cityDetail object containing all the data (including the full street plan).
Depending on your situation you might repeat this pattern for the buildings.
You can then return the city object in your list call and only if a get by id is performed you would return the cityDetail object.
The bad => your api is sorta "inconsistent" as the city objects you get via a list are not the same as the ones you get via the get. You could make 2 resources: city & cityDetail with cityDetail not having a List function and city not having a getByID function but still it's not as clean & predictable as a single resource.
The good => Performance wise & usage wise this usually is a perfect match. You will never show a list of cities with streets so the city object would be sufficient. When you are viewing a single city it is very likely you want to show all data including streets(or at least use this data on that page) so the cityDetail object would fit here as well.
Performance wise it's kinda obvious that fetching 1 milion streets for a getAllMyCities call is overkill ;)