how to save values in database through service api laravel - api

I m beginner in laravel 5, i want to know how to write service api for save the values which passing from mobile app.. Example register user in mobile app and pass those data throghu REST api to db.
Please advice

Jzon - Laravel provide very friendly documentation for beginners like you. Most of things are explained on documentation page mentioned below - Please go through link once - http://laravel.com/docs/5.1/authentication#authentication-quickstart.
Lastly, quick hint for you, when ever you return an array from controller laravel default gives JSON response for you..
e.g. I am in TasksController
public function show($id) {
$task = Task::findOrFail($id);
return $task->toArray()
}
this would give Json.

Related

Can prisma achieve the same things as graphql?

I'm having a hard time understanding what graphql can achieve on top of prisma besides having a singular endpoint.
I've been hearing that the main selling point of graphql is the fact that you are able to query for the specific fields you want to receive, but can't that also be achieved with prisma using the "select" property?
const users = await user.findMany({
select: {
email: true,
},
});
Thank you for your answers!
I understand your confusion. I'll try to make the difference between Prisma and GraphQL clearer for you.
Prisma
Prisma is an ORM like tool. This means that it helps you search for data in your database. Helps you create queries, join data and etc. Prisma is a tool that lives in your back-end (usually) and helps you find the data that you will send to your front-end or mobile application.
GraphQL
GraphQL is a way to communicate with your back-end. So let's say that you want get the name of a user based on its id. On a REST API (that is the more common way) you would send a GET request to the server, and it would respond with a JSON with all of the data for this user.
// Imagine this is your request to the server
await api.get(http://myserver.com/user/1)
// Imagine this is your JSON response
{
name: "Person",
age: 24,
address: "Avenue Street, number 7",
...
}
You see that even though you just wanted the name of the user you got all of the data, when using a REST API. But with GraphQL that is not the case. You can request for only the data that you want.
// Your request to the server would look like this
{
GetUserById(1) {
name
}
}
// In the response you would be getting a JSON with only the data that you requested
{
name: "Person"
}
That is what GraphQL is used for, requesting specific data to your back-end and receiving only what you need. In both cases, REST API and GraphQL, you can use Prisma. It will help you search in your database for the data that was requested.
If you want to know more about Prisma you can check their website where you will find more about how it works and how to use it.
If you want to know more about GraphQL you can check their FAQ page
You can also learn how to use Prisma and GraphQL together

Sharepoint error: Likes are not supported in this item

I'm trying to create a Sharepoint iOS app and using the rest api I get the error "Likes are not supported in this item." after doing a POST to https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')/like.
Anyone knows more about this kind of error?
The Rating settings seems to be set correctly on the Sharepoint server, because the like option works correctly on the website, and also in the app I can see the likesCount properties on the response for the Rest API call https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234').
I don't think there is something wrong with the client app implementation, but it is something related to the Sharepoint configuration, although I haven't seen any more settings in regards to the Rating settings including the Sharepoint access for the mobile app.
The web seems to handle this using the Microsoft.Office.Server.ReputationModel.Reputation.setLike function which again works correctly on the web parts, but I couldn't find a way to do it from the mobile app.
To set Likes for the list item, we need use the API below with POST request.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
And pass the data of the POST request as below.
var item = {
"__metadata": { "type": "SP.Data.PagesItem"},
"LikedByStringId": {"results": ["11"]},
"LikesCount": 2
};
Before set Likes for the item, we need get the "LikedByStringId" and "LikesCount" value of the list item using API below with GET request, then set the new one.
https://tenant.sharepoint.com/News/_api/web/lists/getbytitle('pages')/items('1234')
Check the article here: Demonstrates how to like/unlike resource via SharePoint REST API

get a blog content dynamically using RESTeasy

I am a Java developer, I want to write my own blogging application (that bloggers use to write their blogs with) i know it may sound crazy but i want it just for learning purpose, i am using JSF EJB Hibernate and RESTeasy tools,i started it i have created the database and the view.
From the information that i collected it is recommended to store the blog content in database(in html text), i find that i can use for that Javascript editor like CKEditor after the blogger write his blog in CKEditor i will concatenate it with a prepared header and footer after that i will store it in the database, and i found out that i can get blog post using RESTeasy API.
As an example(sorry):
after the blog is stored in the database
i want to present it to visitors like this:
link containing a path and the id of the article
<div>
Read More...
</div>
when the visitor press the link a REST Controller handle the request, fetch the article from the database using the provided id in the link and return an html page (without creating it statically).
The RESTeasy part perhaps something like this:
#Stateless
#Path("/article/")
public class ArticleResource {
#EJB
private ArticleService articleService;
#GET
#Path("/{id}")
#Produces(value = MediaType.TEXT_HTML)
public Response getArticleById(#PathParam("id") Long id){
//get article post from the database
Article article = articleService.findById(id);
//something here i didn't know
//return article post as an html page
}
}
Please if there is anything here that you see is wrong feel free to inform me, i am just learning here. And if there is an even better approach that you see is good, i really appreciate it.
I know perhaps using Spring it can be better but i want just to learn here how to do it.
I want to know how to get an html page stored in database using JAXRS,
the html page has no file in the application it is just stored in the database something like this:
"<html><head>...</head> <body>...content of the blog here</body> </html>"
Thank you in advance.

Yii Framework, JSON API, Restricted by URL

I am trying to build an API service for my Yii based website,
I have create an API controller with all the functions that returns objects in JSON format.
I also created a system to generate API keys for a specific URL... but I cant seem to understand how to detect the url from where the call is being made to my api so I can compare and validate.
I have tryed with HTTP_REFERER ...not working...
Any idea how is this possible ?
Thanks
try this:
Yii::app()->request->urlReferrer
or
Yii::app()->request->host
or
Yii::app()->request->hostAddress
for more details see http://www.yiiframework.com/doc/api/1.1/CHttpRequest

how to use MethodAuthorizer in Restlet?

I'm currently working on a project with Restlet API.
Now, my router routes 6 different URI's to 6 different Resources.
What i want to do is only to restrict DELETE and PUT methods in 2 of my resources to only authorized users.
I couldn't find any example or tutorial that i can learn about MethodAuthorizer. Is there any easy way to do this?
I tried to use the MethodAuthorizer the same way we can use the RoleAuthorizer (explained here - see the sample code at bottom of the page)
Router router = new Router(getContext());
router.attach("/your/path", YourResource.class);
MethodAuthorizer ma = new MethodAuthorizer();
ma.getAnonymousMethods().add(Method.GET); // your allowed method for all user
ma.getAuthenticatedMethods().add(Method.DELETE); // your allowed method to authenticated user
ma.setNext(route);
rootRouter.attach("/admin", ma);
But it doesn't seem that it is the way to go :(
However if you take a look at the workflow of the security API, I shouldn't be to far from the solution.