JSONAPIAdapter - Use camel case instead of dasherized case - ember-data

Is there a quick and easy way to use camel case when serializing a JsonApi model? By default is is using dasherized case for both url and field names.

Look at EmberJS guides for an example how to make user-profile-related adapter hit user_profile instead:
export default DS.JSONAPIAdapter.extend({
pathForType: function(type) {
return Ember.String.underscore(type);
}
});
Requests for person would now target /person/1. Requests for user-profile would now target /user_profile/1
If you need to serialize attributes, not just the model names, you can find related section to the topic at the very same place, direct link here.
Since the example above uses Ember.String.underscore(), I am attaching a link to very useful String helpers Ember provides by default, Ember.String API:
camelize
capitalize
classify
dasherize
decamelize
htmlSafe
loc
underscore
w

Related

Mockoon | Configure mockoon with a seed to always return the same random data between requests

Although I am using faker to generate random data I would like the responses of a given endpoint to be the same on every request.
I noticed the general settings have an input text for setting a seed but does nothing regarding what I am aiming at.
Faker.js seeding is not always generating the same information.
Instead, it will always generate the same sequence. I'm not sure it's documented on Faker.js' website, but I added this to Mockoon's documentation.
If you want the answer to always be the same you can either:
use the inline body with "static" data (without templating), something like:
{
"username": "john"
}
use the data buckets feature as they are only generated once when the server starts.

Bind Key Vault settings to class

In ASP.NET Core, if reading configuration from a JSON app.settings file I can bind a section to an object like this:
services.Configure<MyPocoConfig>(Configuration.GetSection("Section"))
Is there a straightforward way to do this with a group of settings that are read from Azure Key Vault? I am following the guide as described in the MSDN documentation here https://learn.microsoft.com/en-us/azure/key-vault/vs-key-vault-add-connected-service#access-your-secrets-in-code
I can manually map them like this:
services.Configure<MyPocoConfig>(myPoco =>
{
myPoco.Option1 = Configuration["Option1"];
myPoco.Option2 = Configuration["Option2"];
});
I just wondered if there was a way to automap them as it works for config stored in app.settings JSON. I'm sure it could be done with reflection but I was hoping there'd be a built in way.
I tried putting the settings into a category using the category--setting syntax described in the article and reading them with services.Configure<MyPocoConfig>(Configuration.GetSection("category")), but this doesn't work.
Edit:
It is now possible as of 2020 to put settings into a category using the category--setting syntax and read them like services.Configure<MyPocoConfig>(Configuration.GetSection("category"))
You can achieve the same by naming your Secret in the following pattern.
Section--Option1
Section--Option2
And you can use the following to get the values by section and .NetCore automatically maps it.
services.Configure<MyPocoConfig>(Configuration.GetSection("Section"))
Refer link https://learn.microsoft.com/en-us/aspnet/core/security/key-vault-configuration?view=aspnetcore-2.2#bind-an-array-to-a-class

laravel 4 pattern filter using a wildcard

I started using Laravel 3 last week, and then found the new 4 release and I'm trying to convert now.
I have a dozen+ routes that I want to deliver to a specific controller method. i.e., "/api/v1/owners/3/dogs/1 or /api/v1/owners/3" to run "myresourcecontroller#processRequest"
In Laravel 3 I was able to use this: (note * wildcard)
Route::any('api/v1/owners*', 'owners#processRequest'); // Process tags resource endpoints
I found this example from the documentation but it gives me an error. I get a NotFoundHttpException.
//[Pattern Based Filters](http://laravel.com/docs/routing#route-filters)
Route::filter('admin', function()
{
//
});
Route::when('admin/*', 'admin');
Not sure what I'm doing wrong? Is there another way to do this?
I don't want to use the Laravel 4 restful controllers, cause they don't seem to conform to complete restful design. i.e., no verbs in the url.
I have all of my processing written, I just need to be able to route to it.
I need to be able to create new records by POST /api/v1/owners or /api/v1/owners/3/dogs
I cannot use /api/v1/owners/create.
I'm trying to avoid having to write a route for every endpoint, i.e.,
Route::any('api/v1/owners/{owner_id}', 'owners#processRequest');
Route::any('api/v1/owners/{owner_id}/dogs/{dog_id}', 'owners#processRequest');
Thank you for any help
You should make use of resourceful controllers as they're a great asset when building an API. The endpoints you described can be achieved using resource controllers and nested resource controllers.
Route::resource('owners', 'OwnersController');
Route::resource('owners.dogs', 'OwnersDogsController');
Would allow you to create an owner with POST localhost/owners and create a dog on an owner with POST localhost/owners/3/dogs.
You can then wrap these routes in a route group to get the api/v1 prefix.
Route::group(['prefix' => 'api/v1'], function()
{
Route::resource('owners', 'OwnersController');
Route::resource('owners.dogs', 'OwnersDogsController');
});
Haven't used Laravel myself, but try any('api/v1/owners/*', (note slash before asterisk) as in the example.

REST API: How to search for other attribute

I use node.js as REST API.
There are following actions available:
/contacts, GET, finds all contacts
/contacts, POST, creats new contact
/contacts/:id, GET, shows or gets specifiy contact by it's id
/contacts/:id, PUT, updates a specific contact
/contacts/:id, DELETE, removes a specific contact
What would now be a logic Route for searching, quering after a user?
Should I put this to the 3. route or should I create an extra route?
I'm sure you will get a lot of different opinions on this question. Personally I would see "searching" as filtering on "all contacts" giving:
GET /contacts?filter=your_filter_statement
You probably already have filtering-parameters on GET /contacts to allow pagination that works well with the filter-statement.
EDIT:
Use this for parsing your querystring:
var url = require('url');
and in your handler ('request' being your nodejs http-request object):
var parsedUrl = url.parse(request.url, true);
var filterStatement = parsedUrl.query.filter;
Interesting question. This is a discussion that I have had several times.
I don't think there is a clear answer, or maybe there is and I just don't know it or don't agree with it. I would say that you should add a new route: /contacts/_search performing an action on the contacts list, in this case a search. Clear and defined what you do then.
GET /contacts finds all contacts. You want a subset of all contacts. What delimiter in a URI represents subsets? It's not "?"; that's non-hierarchical. The "/" character is used to delimit hierarchical path segments. So for a subset of contacts, try a URI like /contacts/like/dave/ or /contacts/by_name/susan/.
This concept of subsetting data by path segments is for more than collections--it applies more broadly. Your whole site is a set, and each top-level path segment defines a subset of it: http://yoursite.example/contacts is a subset of http://yoursite.example/. It also applies more narrowly: /contacts/:id is a subset of /contacts, and /contacts/:id/firstname is a subset of /contacts/:id.

How to enable dojox.data.JsonRestStore access struts2's action to retrieve data? I mean how to configure 'target' or others

I tend to use dojox.data.JsonRestStore as my grid's store, but I am always failed to access struts2 action, I am unfamiliar in REST, is it only can be used in servlet rather than struts2, etc.
Currently, My project is using struts2 + spring as backend skill and dojo as front-side skill, have you any ways for me to make dojox.data.JsonRestStore access a structs2 action class?
Thanks in advance.
to get the data, all you need is an HTTP GET that returns an array of JSON objects. The return value from the action must be a string with something like:
[
{
"penUser":"Micha Roon",
"submitTime":"12.03 13:20",
"state":"Eingang",
"FormNumber":"001001"
},
{
"penUser":"Micha Roon",
"submitTime":"12.03 13:20",
"state":"Eingang",
"FormNumber":"001001"
}
]
If you want to be able to update objects you have to have a method that reacts to PUT with the same URL as the one you used for GET and if you need to delete, DELETE will be used. The important part is that it must be the same URL.
In order to have JsonRestStore pass the ID in a GET parameter instead of appending it to the URL, you could specify the URL like so:
target:"services/jsonrest/formstore?formId="
When you call yourStore.get("123") the request will try to get http://yourserver:port/AppContext/services/jsonrest/formstore?formId=123
REST is nothing more than a convention.
You can use a RESTFull API like jersey.java.net in order to make your life easier and your URL more RESTFull.